1. Use the submit button to submit and perform form verification on the onsubmit event in the Form:
CopyCode The Code is as follows: <SCRIPT type = "text/JavaScript">
Function onsub (){
// Form Verification Code
}
</SCRIPT>
<Form action = "" method = "" onsubmit = "javascript: onsub ();">
2. Use the onclick event of a button or image to call the Form Verification Code:Copy codeThe Code is as follows: <input type = "button" name = "button" id = "button" onclick = "javascript: onsub ();"/>
However, when you use the second method to submit a form, you cannot press enter to submit the form. This gives the customer
The experience is different from using the submit button to submit a form. To implement this function, you only need to add the following JavaScript code to your page.Copy codeThe Code is as follows: function butonclick (){
If (event. keycode = 13 ){
VaR button = Document. getelementbyid ("bsubmit"); // bsubmit is the ID of the botton button
Button. Click ();
Return false;
}
}
You can call the butonclick () function for the onkeydown event in the most input field of your form. For example, log onProgramIs the password
<Input type = "password" name = "userpwd" onkeydown = "javascript: butonclick ();"/>
In this way, after entering the password, you can press the Enter key to verify the form and log on (if the user name and password are correct ). This is my personal summary and shared.
Let's share it!