Problem with Javascript not inputting value into hidden fields
-
08-07-2019 - |
Question
Maddening problem here.
When my page loads: <body onload="getClientDateTime();">
It runs this function: document.getElementById('ClientDateTime').value="hello world";
Which theoretically should insert "hello world" into a hidden field: <INPUT TYPE="hidden" name="ClientDateTime" id="ClientDateTime" value="">
But she no worky.
If I change the field to type "text" then it works like it should but not as a "hidden". Please help!
Solution
This actually works as it alerts the correct value:
<html>
<head>
<title>Test</title>
</head>
<body onload="document.getElementById('ClientDateTime').value='hello world'; alert(document.getElementById('ClientDateTime').value);">
<input type="hidden" name="ClientDateTime" id="ClientDateTime" value="" />
</body>
</html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow