Js cursor location text box carriage return form submission Solution

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.