Sometimes, we want to submit the form on change of dropdown list with JavaScript.
In this article, we’ll look at how to submit the form on change of dropdown list with JavaScript.
How to submit the form on change of dropdown list with JavaScript?
To submit the form on change of dropdown list with JavaScript, we call submit
on the form.
For instance, we write
<form action="myservlet.do" method="POST">
<select name="myselect" id="myselect" onchange="this.form.submit()">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
</select>
</form>
to set the onchange
attribute to this.form.submit()
to submit the form that the select element is in when we change the selection.
Conclusion
To submit the form on change of dropdown list with JavaScript, we call submit
on the form.