Js cursor location text box carriage return form submission Solution
This article describes how to solve the js cursor position text box press ENTER form submission problem. Share it with you for your reference. The specific analysis is as follows:
When the cursor is positioned in the text box of the secondary search, press enter to return the json string returned by the method.
Cause: When there is only one single-line text input field in a form, the user agent shocould accept Enter in that field as a request to submit the form.
When there is only one input type = "text" in form, the user presses the Enter key to submit the form.
Solution: handle the onkeydown event of input text and disable the carriage return operation.
Code:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<P> <Input class = "text-1" type = "text" name = "name" Id = "notAssociateName" value = "" onkeydown = "enter_down (event);"/> </P> Function enter_down (event ){ If (event. keyCode = 13 ){ StopDefault (event ); } } Function stopDefault (e ){ // If the event object is provided, this is a non-IE browser If (e & e. preventDefault ){ // Block the default browser action E. preventDefault (); } Else { // Block the default action of the function in IE Window. event. returnValue = false; } Return false; } |
I hope this article will help you design javascript programs.