简体   繁体   中英

Submit form on change of input field

I have a form with multiple input checkbox fields. I want to trigger form submit on change in any of the checkbox without submit button.

<form action="" method="get">
  <input type="checkbox" name="p[]" value="1">
  <input type="checkbox" name="p[]" value="2">
  <input type="checkbox" name="p[]" value="3">
</form>

How it can be done with jQuery?

You could hook to the change() event of the checkboxes, then fire a submit() on the parent form , like this:

$('form input').on('change', function() {
    $(this).closest('form').submit();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM