Reputation: 71208
I have this form in my HTML:
<form action="/awe/ChangeTheme/Change" method="post">
<select id="themes" name="themes">
...
<option value="blitzer">blitzer</option>
</select>
<input type="submit" value="change" />
</form>
Anybody knows how to submit it when a value is selected in the 'themes' dropdown?
Upvotes: 26
Views: 70457
Reputation: 743
$(function() {
$('#your_select_field_id').on('change', function(e) {
$('#your_form_id').submit();
})
})
This solved my problem efficiently.
Upvotes: 0
Reputation: 2343
In case your html contains more than one form
$(function() {
$('#themes').on('change', function(e) {
$(this).closest('form')
.trigger('submit')
})
})
Upvotes: 6
Reputation: 38400
The other solutions will submit all forms on the page, if there should be any. Better would be:
$(function() {
$('#themes').change(function() {
this.form.submit();
});
});
Upvotes: 78
Reputation:
I recommend using the longhand bind method because it has the same effect as the shorthand supplied by the other answers, but you can add additional events if need be without having to change your code.
$("#themes").bind("change", function() {
$("form").trigger("submit");
});
Upvotes: 2
Reputation: 1038810
$(function() {
$('#themes').change(function() {
$('form').submit();
});
});
Upvotes: 1