3

I try to set some hidden form field values with an onclick event. Ok, after I did something like this:

document.getElementById('hidden_field').value = 123;

I can output the value with the firebug console by entering this:

alert(document.getElementById('hidden_field').value);

So the values are definitely set. But now when I submit the form, the hidden field values are still empty.

Do you have any idea whats going wrong?

3
  • 2
    You will need to post your HTML Commented Jun 3, 2010 at 12:36
  • Check if your 'hidden_field' is inside the form element, it contains name and id attributes and form is posted correctly. Commented Jun 3, 2010 at 12:37
  • 1
    You can install something like TamperData to see what's in the actual HTTP request/response blocks. Commented Jun 3, 2010 at 12:37

1 Answer 1

12

Make sure your hidden field has the name attribute:

<input id="hidden_field" name="hidden_field" type="hidden" value="123" />

Inputs without a name attribute aren't sent with the request.

Sign up to request clarification or add additional context in comments.

3 Comments

And note also (this is for the OP Andy, not you :-) that your <input> can have both "id" and "name" attributes, and if desired the values of those attributes can be the same. Only one element on a given page can have a particular "id" value, however.
@Pointy: even though the comment wasn't directed at me, you made a good point and I edited my answer to reflect that, using the id given in the example by the OP :-)
Thank all of you for your quick answer :) I use the symfony php framework. In the template there was a method that renders all hidden fields automatically. And I did it by hand, too. So one field was filled the other not. Now it work, thx.

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.