In a .php file containing other HTML, I use PHP code to build a string of HTML prior to the <head> tag of the page, of which contains a hidden input field as such:
In a .php file containing other HTML, I use PHP code to build a string of HTML prior to the <head> tag of the page, of which contains a hidden input field as such:
...
Can you please tell me where the error is here?
Thank you.
For starters there shouldn't be any input elements, hidden or otherwise, prior to the <head> tag. They should all be in the <body>
Thanks for the reply. The <input> tag isn't actually above the <head> tag, it is merely built in a php string there. To clarify a little, this is sort of what the .php file looks like:
var NUM_QS = document.getElementById("NUM_QS").value;
is being executed in the <head> and so the element with id = NUM_QS doesn't exist yet and so you are getting the error message. You can't access elements until they have been loaded in the <body>
Either put that statement in a window.onload which means it won't be executed until the window and all its elements have been loaded or link to your external js just above the </body> at which point all the elements should have been loaded by then.
Bookmarks