Form, carriage return, trigger event

Source: Internet
Author: User

// Press enter in the gridview text box to trigger the Button event
<Script type = "text/javascript" language = "javascript">
Function clickButton ()
{
If (event. keyCode = 13)
{
Document. all ('ibtnupdate'). click ();
Return false;
}
}
</Script>
<Asp: TextBox ID = "TextBox3" onkeypress = "return (clickButton ();" runat = "server">
 
 
 
 
 
 
 
<Script type = "text/javascript" language = "javascript">
 
Function KeyDown () // block the carriage return event
{
If (event. keyCode = 13)
{
Return false;
}
}
 
Function EnterTextBox () // press enter in the final text box to trigger submission
{
If (event. keyCode = 13 & document. all ["txtCode"]. value! = "")
{
Document. all ['btnup']. focus ();
Document. all ['btnup']. click ();
Return false;
}
}
 
</Script>
 
<Form id = "form1" runat = "server" onkeypress = "return KeyDown ()"> // block the carriage return event
 
This.txt Code. Attributes. Add ("onkeypress", "EnterTextBox ()"); // press enter in the final text box to trigger submission
 
/*

1. If there is a type = "submit" button in the form, the Enter key takes effect.
2. If there is only one input of type = "text" in the form, no matter what type the button is, the Enter key takes effect.
3. If a button uses a button instead of input, and no type is added, type = button is used by default in IE, and type = submit is used by default in FX.
4. Other form elements, such as textarea and select, do not affect the trigger rule. radio checkbox does not affect the trigger rule. However, in FX, the Return key is returned and the response is not returned in IE.
5. The input of type = "image" has the same effect as type = "submit". I don't know why such a type is designed. It is not recommended, you should use CSS to add a background image.
In actual application, it is easy to make the form respond to the carriage return key, and ensure that there is a type = "submit" button in the form. What if there is only one text box that does not want to respond to the Enter key? My method is a bit awkward, that is, to write another meaningless text box and hide it. According to the 3rd rules, we try to explicitly declare the type when using the button to make the browser consistent.
 
*/
 
 
// Be sure to add return
// The background event is executed only when the verification is passed.
BtnLogin. Attributes. Add ("onclick", "return checkLoginForm ();");

Author "xueinsz"
 

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.