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