How to submit a form on change?

谁说我不能喝 提交于 2019-12-11 06:33:25

问题


The question is specifically about the Captive Network Assistant.

I have tried using vanilla JavaScript,

<form action="">
    <select name="test" onchange="this.form.submit()">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
    </select>
</form>

As well using jQuery, in case there was a browser incompatibility issue.

$('select').on('change', function () {
    $(this).closest('form').submit();
});

However, none of them work and Captive Portal issues are not an easy cookie to debug. Is there a known solution?


回答1:


Your code looks fine. You probably want to fill in the action attribute of your form and possibly use the method and enctype attributes as well.

Here is a working copy of your code on jsFiddle




回答2:


As i remember submit() method doesn't work properly in jQuery.

Try using JavaScript: document.getElementById('ID').submit();

I had similar problem but this solved everything, so hole it helps You.



来源:https://stackoverflow.com/questions/16767871/how-to-submit-a-form-on-change

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