Several ways to submit a form by carriage return

Source: Internet
Author: User

Analysis of the principle of submission is generally based on the user's key one, enter the keycode=13, know that we can judge, as long as the use of JS monitoring keyboard, if it is 13 on the submission form on it.

The main function to implement is: After entering data in the text box, press ENTER to submit (that is, press ENTER to search, press the search button can also search)
Code A
How to implement the text box focus automatic jump and submit the form through the ENTER key
1.

<script language= "VBScript" >
<!--
Sub Document_onkeydown
If Window.event.keycode=13 Then
Window.event.keycode=9
End If
End Sub
-->
</script>

To perform the TAB key when clicking enter

Code two

Steps:

<script type= "text/web Effects" language= "JavaScript" >
function KeyDown ()
{
if (Event.keycode = 13)
{
Event.returnvalue=false; Do not refresh the interface
Form.btnok.click (); Use form Submit
}
}
</script>

Note: If the query button is a document.getElementById ("ImageButton1") when submitting the form with the ImageButton control. Click ();

<asp Tutorial: TextBox id= "TextBox1" runat= "Server" ></asp:textbox>
<br/>
<asp:textbox id= "TextBox2" runat= "Server" onkeydown= "KeyDown ()" ></asp:textbox>
<br/>
<asp:button id= "Btnok" runat= "Server" onclick= "Btnok_click" text= "OK"/>


Code Three

<script language= "JavaScript" >
function AA ()
{
if (Event.keycode = 13)
{
Event.returnvalue=false;
Event.cancel = true;
Document.all.imagebuttonsearch.click ();
}
}
</script>

To control these behaviors, no need to use JS, the browser has helped us do these processing, here summed up a few rules:
1, if the form has a type= "submit" button, enter the entry into force.
2, if the form has only one type= "text" input, enter the entry into force.
3, if the button is not with input, but with button, and without type,ie default for type=button,fx default for Type=submit.
4, other form elements such as textarea, select does not affect.

In practical applications, it is easy to make the form respond to the ENTER key, ensuring that there is a type= "submit" button on the form. And what happens when you have only one text box and don't want to respond to enter? My method is a little awkward, is to write a meaningless text box, hidden

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.