Reputation: 4558
I have a form with a <select>
on the page. when the user selects an option, I want the form to submit itself. How can I do this?
Thanks
Upvotes: 0
Views: 1125
Reputation: 1038810
You could subscribe for the .change()
event on the dropdown and invoke the .submit()
method of the containing form:
<form action="/" method="post">
<select id="myDropdown">
<option value="1">item 1</option>
<option value="2">item 2</option>
...
</select>
...
</form>
and then:
$(function() {
$('#myDropdown').change(function() {
$(this).closest('form').submit();
});
});
Upvotes: 2
Reputation: 66
$('select').change(function(){$('form').submit();});
Needless to sayyou should be doing some more checking etc in there...
Upvotes: 0
Reputation: 997
<form name="foo">
<select onchange="document.foo.submit();"></select>
</form>
Upvotes: 1