Press ENTER to perform a click or search problem

Source: Internet
Author: User

Recently need to press the button search function, instead support press ENTER enter key, search.

Implementation by pressing ENTER, the Click event is still relatively simple.

Press ENTER to search for a user
$ (window). KeyDown (function (event) {
Alert ("You pressed the key");
if (Event.keycode = = 13) {
Alert ("You pressed enter");

var Source = $ ("#<%=button1.clientid%>"). Click ();
document.getElementById ("<%=button1.clientid%>"). Click ();
return false;


The above code will be able to implement this function.

But when implemented, found to press ENTER multiple times to search for results, and then led to say that the form form by default press ENTER to submit the form, so very depressed, because the master page.

Can not run out of the Master Page form form, how to do, and finally found that after the Click event returned false, prevent form form submission, and finally solve the problem perfectly.

How to Prevent carriage return (enter) key to submit a form, in fact very simple, just a word. Onkeydown= "if (event.keycode==13) return false;" Just write this sentence in the from tag.

Press ENTER to perform a click or search problem

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