0

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!

6
  • How are you verifying that it got changed? Commented Oct 28, 2009 at 19:23
  • Works for me in FF on the mac with a blank slate webpage. You sure you're not doing something else wrong? Commented Oct 28, 2009 at 19:27
  • It does seem to work, at least on Firefox. Are you viewing the source to verify the value isn't changing? Depending on the browser you're using that may reload the page and show you the source before any javascript is executed. Commented Oct 28, 2009 at 19:29
  • I verify it by checking the page source after it has run and it's still blank. Commented Oct 28, 2009 at 19:32
  • This modification won't be reflected in the View Source as it is done with Javascript. So what you've done actually works, it is just that you are not using the correct method to verify it. Commented Oct 28, 2009 at 19:35

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, that alerts the correct value, but the hidden field's value is still blank. So when I got to submit this form, there is nothing in there.
Maybe just because the source code isnt' changed that it's still really in there? I'm going to run a test and see...
Yep, it was actually changed, just not in the View Source. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.