Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 331
Anuj TBE Avatar asked Aug 03 '16 08:08

Anuj TBE


People also ask

How do I submit a form on select Change?

You can do it using a simple javascript. Here onChange event will be invoked whenever user changes the value in the select box and this. form. submit() method will submit the form.

How do you change the input type on a submit text?

Input value attribute The value attribute can be used to change the text of the form submit button. Use value attribute within <input> of type="submit" to rename the button.

How do you reset input value after submitting?

To clear an input field after submitting:Add a click event listener to a button. When the button is clicked, set the input field's value to an empty string. Setting the field's value to an empty string resets the input.


1 Answers

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();
});
like image 196
Rory McCrossan Avatar answered Oct 17 '22 11:10

Rory McCrossan