views:

187

answers:

2

HI volks,

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?

Thx for your answers.

+1  A: 

Check if your 'hidden_field' is inside the form element, it contains name and id attributes and form is posted correctly.

Nilambari
+3  A: 

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.

Andy E
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
@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 :-)
Andy E
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.