assign value to hidden field when checkbox checked javascript

≯℡__Kan透↙ 提交于 2019-12-25 05:07:51

问题


I need to store the values in the hidden text field when I select any check box from the page

    <input type="checkbox" name="checked1" value="checked1" onselect="getvalue()">
<input type="checkbox" name="checked1" value="checked2" onselect="getvalue()">
<input type="checkbox" name="checked1" value="checked3" onselect="getvalue()">

When I any of the check box that will store into below hidden field:

<input type="hidden" />

回答1:


Using jquery, and assuming you gave an id (here "myhidden") to your hidden input, you can do this :

$('input[type="checkbox"]').change(function(){
    $('#myhidden').val($(this).val());
});

This fiddle demonstrates it : http://jsfiddle.net/dystroy/e6jpG/



来源:https://stackoverflow.com/questions/10716945/assign-value-to-hidden-field-when-checkbox-checked-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!