Set hidden form field values ​​using JavaScript, but request an empty one

I am trying to set some hidden form field values ​​using the onclick event. Ok, after I did something like this:

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

I can output the value using the firebug console by typing this:

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

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

Do you have any idea what is going wrong?

+3
source share
1 answer

Make sure your hidden field has an attribute name:

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

Entries without an attribute are namenot sent with a request.

+10
source

Source: https://habr.com/ru/post/1748340/


All Articles