One is submitted with submit. One is to submit with a button.
Method One:
Insert a JS method in the header of the front page of the JSP:
function CheckUser () {
var result = document.getElementById ("userid"). Value;
var password = document.getElementById ("Userpassid"). Value;
if (result = = "") {
Alert ("User name cannot be empty");
return false;
}
if (password = = "") {
Alert ("Password cannot be null");
return false;
}else{
return true;
}
}
Write this in the form form:
<form id= "Formid" Name= "myform" method = ' post ' action = ' user_login_submit.action ' onsubmit = ' return CheckUser (); " >
<table width= "100%" border= "0" >
<tr>
<TD width= "height=" align= "right" > User name </td>
<td><input type= "text" value= "" class= "text2" name = "username" id = "userid"/></td>
</tr>
<tr>
<TD width= "height=" align= "right" > Secret code </td>
<td><input type= "password" value= "" class= "text2" name = "Userpass" id = "Userpassid"/></td>
</tr>
<tr>
<TD width= "height=" align= "right" > </td>
<td><div class= "C4" >
<input type= "Submit" value= "class=" btn2 "/>
Method Two:
Button Submit
function CheckUser () {
var result = document.getElementById ("userid"). Value;
var password = document.getElementById ("Passid"). Value;
if (result = = "") {
Alert ("User name cannot be empty");
return false;
}
if (password = = "") {
Alert ("Password cannot be null");
return false;
}
document.getElementById ("Formid"). Submit ();
}
Form form, need to write ID
<form id= "Formid" method = ' post ' action = ' user_login_submit.action ' >
The button buttons are written as follows:
<input type= "button" value= "" class= "btn2" onclick = "checkUser ();"/>
Two ways to submit form forms, submit and button usage