开发者

jQuery submit form on checkbox press

开发者 https://www.devze.com 2023-02-06 21:18 出处:网络
I am trying to submit a form on 开发者_高级运维checking or unchecking a checkbox using jQuery and using the data value of that checkbox, can someone help me on how to do this?The requirement of submit

I am trying to submit a form on 开发者_高级运维checking or unchecking a checkbox using jQuery and using the data value of that checkbox, can someone help me on how to do this?


The requirement of submitting the value of the box you just un-checked is the unusual bit here. One option is to stuff that value into a hidden field, which will be submitted. So:

<input name="checkbox_trigger" id="checkbox_trigger" value="" type="hidden" />

Then:

$('#yourcheckbox').click( function(e){
  $('#checkbox_trigger').val( e.value ); // capture on check or uncheck
  $(this).closest('form').submit();
});

If the name of the checkbox is also significant, you can easily follow this pattern to capture the field name as well.


i think you should try using .trigger

i think there is a trigger submit

$('#yourElement').live('click', function(){
    $('#yourForm').trigger('submit');
})
0

精彩评论

暂无评论...
验证码 换一张
取 消