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?
For starters there shouldn't be any input elements, hidden or otherwise, prior to the <head> tag. They should all be in the <body>
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.