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 badges
Add a ment  | 

3 Answers 3

Reset to default 4

How 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.

本文标签: javascriptDisable form submission on pressing enter because i am using Ajax functionalityStack Overflow