最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Set hidden form field values with JavaScript but request still empty - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited Apr 19, 2014 at 7:48 tshepang 12.5k25 gold badges97 silver badges139 bronze badges asked Jun 3, 2010 at 12:32 ownkingownking 2,0061 gold badge26 silver badges34 bronze badges 3
  • 2 You will need to post your HTML – Keith Rousseau 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. – Nilambari 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. – Pointy Commented Jun 3, 2010 at 12:37
Add a ment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论