JavaScript Submit Form Detail procedure by carriage return

Source: Internet
Author: User

Press ENTER in different places to get a different response
If you have more than one text box (textbox) on the same page, each text box corresponds to a different submit button (a button), as in the following "login" pages, there are "Enter the mailbox Number" and "Enter account" two text boxes and "Enter the mailbox", "Enter the Community" two buttons.

The implementation steps are as follows:

1. Create pages and code files (this step is not described in detail)
2. Add onkeydown= "KeyDown ()" to the form to mask the return response of the page
The code for KeyDown () is as follows:
function KeyDown () {}
3. Add onkeydown= "mail ()" To the text box "Enter the mailbox number". Let it respond to the "Enter Mailbox" button event
The Mail () code is as follows:

function mail ()
{
if (event.keycode==13)
{
Document.all.mail.click ();
Alert (' Mail ');
}
}

4. Add onkeydown= to the "Enter Account" text box "BBS ();" Let it respond to the "Enter Community" button event
The BBS () code is as follows:

Function BBS ()
{
if (event.keycode==13)
{
Document.all.bbs.click ();
Alert (' BBS ');
}
}

Let's take a look at how to handle the carriage return

<script language= "Web Effects" for= "document" event= "onkeydown" >
Carriage return button Event handling
if (Event.keycode = = 13) {
event.keycode=0;
var list=document.getelementsbytagname ("input");
for (var i=0;i<list.length && list[i];i++)
{
if (List[i].id.indexof ("Ibtnnextstep") >0) {//id contains a button with the word "ibtnnextstep"
List[i].click ();
}
if (list[i].id== "Btnsave") {
List[i].click ();
}

if (list[i].id== "Btnsumbit") {
List[i].click ();
}
}
return false;
}
</script>

Press RETURN to pay attention to focus issues, you must cause the text input box to lose focus. Getting the focus from another control is tantamount to losing focus to the text input box.

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.