How to Use carriage return to replace the TAB when entering a form _ form Effect

Source: Internet
Author: User
When filling out a form, use carriage return instead of TAB. The key is tabindex, which is designed to set a tabindex for each form element, the value is the value of tabindex of the previous form Element plus one. The function is to add one value of the current tabindex when you press the Enter key, then compare them one by one with the tabindex value of each form element. If they are equal, move the focus to the form element.

First, we need to set an onkeyup event in the form body:


Second, set a tabindex value for each form element. Assuming that the form has three elements, we set the tabindex values as follows:




Finally, write the changefocus function as follows:
Function newinfo_form_onkeyup ()
{
Key = window. event. keyCode;
If (key = 0xD) // determines whether to press the Enter key
{
CurTabIndex = event. srcElement. tabIndex 1 // Add the value of the current tabindex to 1
For (n = 0; n {
If (newinfo_form.elements [n]. tabIndex = CurTabIndex) // locate the next form Element
{
Newinfo_form.elements [n]. focus (); // move the focus
Return true;
}
}
}
}
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.