To summarize the form submission method: 1. Use the submit button to submit. When you click the submit button, the onclick event is triggered. The function in JavaScript determines whether the input content is empty. If it is empty, it returns false and does not submit. If it is not empty, it submits to the address specified by action. <script type="text/javascript"> function check(form) { if(form.userId.value=='') { alert("Please enter your user account!"); form.userId.focus(); return false; } if(form.password.value==''){ alert("Please enter your login password!"); form.password.focus(); return false; } return true; } </script> <form action="login.do?act=login" method="post"> User Account<input type=text name="userId" size="18" value="" ><br> Login password<input type="password" name="password" size="19" value=""/> <input type=submit name="submit1" value="Login" onclick="return check(this.form)"> </form> 2. Use a button to submit. When you click the button, the onclick event is triggered. The function in JavaScript determines whether the input content is empty. If it is empty, it returns false and does not submit. If it is not empty, it submits to the address specified by the action. Since the button does not have the function of automatic submission, submission is implemented by JavaScript. <script type="text/javascript"> function check(form) { if(form.userId.value=='') { alert("Please enter your user account!"); form.userId.focus(); return false; } if(form.password.value==''){ alert("Please enter your login password!"); form.password.focus(); return false; } document.myform.submit(); } </script> <form action="login.do?act=login" name="myform" method="post"> User Account<input type=text name="userId" size="18" value="" ><br> Login password<input type="password" name="password" size="19" value=""/> <input type=button name="submit1" value="Login" onclick="check(this.form)"> </form> 3. Use the submit button to implement submission. When the submit button is clicked, the onsubmit event is triggered first. The function in JavaScript determines whether the input content is empty. If it is empty, it returns false and does not submit. If it is not empty, it submits to the address specified by action. <script type="text/javascript"> function check(form) { if(form.userId.value=='') { alert("Please enter your user account!"); form.userId.focus(); return false; } if(form.password.value==''){ alert("Please enter your login password!"); form.password.focus(); return false; } return true; } </script> <form action="login.do?act=login" method="post" onsubmit="return check(this)"> User Account<input type=text name="userId" size="18" value="" ><br> Login password<input type="password" name="password" size="19" value=""/> <input type=submit name="submit1" value="Login"> </form> The above are the three common ways to submit forms. If you have any questions, please feel free to contact me on QQ: 317856821 This is the end of this article about the detailed case study of HTML form submission method. For more relevant HTML form submission content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Analysis of MySQL cumulative aggregation principle and usage examples
First, what is database partitioning? I wrote an ...
Table of contents Overall Effect Listen for conta...
Table of contents 1. Introduction 2. Environmenta...
In Vue, we can define (register) local components...
Copy code The code is as follows: <!DOCTYPE ht...
Table of contents 1. Index Basics 1.1 Introductio...
Table of contents cache Cache location classifica...
In this article, we sorted out the startup proces...
This article shares the specific code of JavaScri...
Today I got familiar with the mouse zooming effect...
1. I purchased a VPS and CentOS system, and found...
After setting the table width in the page to width...
This article uses examples to describe the creati...
What is a generator? A generator is some code tha...
1. Command method Run the nginx service in the cr...