admin管理员组文章数量:1404355
I am using ajax functionality. When i am selecting any suggestion using enter key, the form get submitted automatically because the submit button is auto-focused. Is there any way to select ajax suggestion using enter key as well submit the form using enter key. Something like when i input the values of all the fields then only submit button get enabled.
I am using ajax functionality. When i am selecting any suggestion using enter key, the form get submitted automatically because the submit button is auto-focused. Is there any way to select ajax suggestion using enter key as well submit the form using enter key. Something like when i input the values of all the fields then only submit button get enabled.
Share Improve this question asked Jan 10, 2011 at 14:01 R. RahulR. Rahul 1,1863 gold badges16 silver badges40 bronze badges3 Answers
Reset to default 4How are you calling your Ajax function? It should be inside the submit
event handler of the form. And then if you have the event handler return false
it won't submit normally:
<form onsubmit="doAjaxSubmit(); return false;">
...
</form>
You can detect which key is pressed using the .keypress()
method. From this you should be able to return false;
for form submit and do your ajax stuff on the back of it in an if
statement:
http://api.jquery./keypress/
You can have your form's onSubmit
return true
if all the fields have values, or false
if they don't.
版权声明:本文标题:javascript - Disable form submission on pressing enter because i am using Ajax functionality - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744796073a2625581.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论