开发者

jQuery: submit form after a value is selected from dropdown

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?


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();
    });
});


$('#themes').change(function(){
    $('form').submit();
});


In case your html contains more than one form

$(function() {
  $('#themes').on('change', function(e) {
    $(this).closest('form')
           .trigger('submit')
  })
})


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");
});


$(function() {
    $('#themes').change(function() {
        $('form').submit();
    });
});


$(function() {
   $('#your_select_field_id').on('change', function(e) {
      $('#your_form_id').submit();
   })
})

This solved my problem efficiently.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜