jQuery: submit form after a value is selected from dropdown

a 夏天 提交于 2019-11-30 08:04:47

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();
    });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!