Question
-
Topic
-
Error retrieving input value in window onload function
My html code displays a table, which includes an input (fname) which After the table, I have this script:
window.onload = function ()
varSepType =document.getElementById(‘fname’).value
window.alert(varSepType );
ChangeSName(varSepType );The purpose of the script is to call a function, which changes the colour of one table element. I don’t want to set the colour in the table, because the function is also called by an onChange and I want the code to not be duplicated.
However, the console says “Uncaught TypeError: document.getElementById(…) is null”, despite the input having am initial value (it is set to a session variable & I can see on screen that it has been set).
I’m using WordPress.
Any ideas, please?