HTML form Form Submission Method Case Explanation

  • 2021-11-13 00:32:04
  • OfStack

form form submission method summary 1 below:

1. Use submit button to realize submission. When submit button is clicked, onclick event is triggered, and the function in JavaScript judges whether the input content is empty. If it is empty, return false without submission. If it is not empty, submit to the address specified by action.


<script type="text/javascript">
         function check(form) {
              if(form.userId.value=='') {
                    alert(" Please enter a 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=" Landing " onclick="return check(this.form)">  
</form>

2. Use button button to realize submission. When button button is clicked, onclick event is triggered, and the function in JavaScript judges whether the input content is empty. If it is empty, return false and do not submit. If it is not empty, submit to the address specified by action. Because button button does not have automatic submission function, JavaScript realizes submission.


<script type="text/javascript">
         function check(form) {
              if(form.userId.value=='') {
                    alert(" Please enter a 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=" Landing " onclick="check(this.form)">  
</form>

3. Use submit button to realize submission. When submit button is clicked, onsubmit event is triggered first, and the function in JavaScript judges whether the input content is empty. If it is empty, return false and do not submit. If it is not empty, submit to the address specified by action.


<script type="text/javascript">
         function check(form) {
              if(form.userId.value=='') {
                    alert(" Please enter a 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=" Landing "> 
</form> 

The above are the three commonly used submission methods of form forms. If you don't understand, welcome qq communication: 317856821


Related articles: