I have a form with a select and a few text inputs. I'd like the form to be submitted when the select is changed. This works fine using the following:
onchange="this.form.submit()"
However, if the form also contains a submit button, then the form does not submit when the select is changed. I'm guessing some kind of conflict.
What are my options here?
Should I use something like $(this.form).trigger("submit")
instead?
The HTML DOM Form submit() method is used for submitting the form data to the address specified by the action attribute. It acts as a submit button to submit form data and it doesn't take any kind of parameters.
If you need to submit a form when a checkbox is checked or when it is unchecked like when you are using a switch, a good way is to create an hidden input. If you try to submit the checkbox argument if the checkbox is unchecked the form will not be submitted at all.
You should be able to use something similar to:
$('#selectElementId').change( function(){ $(this).closest('form').trigger('submit'); /* or: $('#formElementId').trigger('submit'); or: $('#formElementId').submit(); */ });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With