Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript select onchange='this.form.submit()'

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?

like image 365
JonoB Avatar asked Aug 31 '11 17:08

JonoB


People also ask

What is this form submit ()?

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.

How submit form if checkbox is checked?

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.


1 Answers

You should be able to use something similar to:

$('#selectElementId').change(     function(){          $(this).closest('form').trigger('submit');          /* or:          $('#formElementId').trigger('submit');             or:          $('#formElementId').submit();          */     }); 
like image 72
David Thomas Avatar answered Sep 17 '22 15:09

David Thomas