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

javascript - Submit form on change of input field - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Aug 3, 2016 at 8:15 Rory McCrossan 338k41 gold badges320 silver badges351 bronze badges asked Aug 3, 2016 at 8:13 Anuj TBEAnuj TBE 9,79034 gold badges146 silver badges304 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 16

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();
});
发布评论

评论列表(0)

  1. 暂无评论