I'm loading a dynamic header with a dynamic hidden input from php by doing an ajax request. The input gets created fine. The problem is not there. Below the same page I'm using plain javascript to get the value of that dynamic input. The Ajax and the javascript are two different codes. If they were not, I would simply load from ajax success but I can't do this here.
Problem is, in the console I get this error :
TypeError: document.getElementById(...) is null
How can I fix this?
hidden input
<input id="appStatus" type="hidden" value="0">
javascript
window.onload = function() {
var app_mode = document.getElementById('appStatus').value;
if (app_mode === 0) {//dev
var stripe = Stripe('pk_test_xxxx');
} else {//live prod
var stripe = Stripe('pk_live_xxxx');
}
};