The first type:
<script type="Text/javascript">function Check (form) {if(Form.userId.value = ="') {alert ("Please enter 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=" -"Value=""> <br>Login Password<input type="Password"Name="Password"Size=" +"Value=""/> <input Type=submit name="Submit1"Value="Login"onclick="return Check (this.form)"> </form>
The second Kind
<script type="Text/javascript">function Check (form) {if(Form.userId.value = ="') {alert ("Please enter 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=" -"Value=""> <br>Login Password<input type="Password"Name="Password"Size=" +"Value=""/> <input Type=submit name="Submit1"Value="Login"> </form>
Third Kind
<script type="Text/javascript">function Check (form) {if(Form.userId.value = ="') {alert ("Please enter 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=" -"Value=""> <br>Login Password<input type="Password"Name="Password"Size=" +"Value=""/> <input Type=button name="Submit1"Value="Login"onclick="Check (this.form)"> </form>
Three ways to submit JS form