Note: The prerequisite for verifying that you are empty is to ensure that it is validated before the form is submitted. If the validation result has an empty entry that restricts the form from submitting, and prompts you to verify the error message and verify that the page properties are not empty, the form is submitted normally, which is part of the JS section, It has nothing to do with the background business logic layer and the control layer.
You can restrict the submission by restricting it in the form label or by adding the OnClick event limit to the Submit button:
<form action= "..." method= "POST" onsubmit= "return check ();" >
<input type= "Submit" value= "submitted" onclick= "return Check ()" >
Case:
Copy Code code as follows:
<form action= "./login.action" method= "POST" onsubmit= "return check ();" >
<table>
<tr>
<TD width= "451" > </td>
<TD width= "378" >
<table >
<tr>
<TD width= > </td>
<td>
<font color= "#000000" > Username:</font>
</td>
<TD align= "Left" > <input name= "userinfo.username" id= "UserName" type= "text" >
<span id= "Checkusername" ></span>
</td>
<tr> <td> </td>
<TD align= "right" nowrap>
<font color= "#000000" > Password:</font>
</td>
<TD align= "Left" >
<input name= "Userinfo.password" id= "password" type= "password" >
<span id= "Checkpassword" ></span>
</td>
</tr>
<tr>
<TD colspan= "4" align= "Center" nowrap>
<input type= "Submit" id= "Btnlog" value= "Login" >
<input type= "reset" value= "reset" >
</td>
</tr>
</table>
</form>
<!--to introduce JS file jquery-->
Copy Code code as follows:
<script type= "Text/javascript" src= "Js/common/jquery-1.5.1.min.js" ></script>
<script type= "Text/javascript" >
function Check () {
var username=$ ("#userName"). Val ();
var password=$ ("#password"). Val ();
alert (userName);
alert (password);
if (username== "") {
$ ("#checkUserName"). HTML ("<font color= ' Red" > Username cannot be empty!) </font> ");
return false;
}
if (password== "") {
$ ("#checkPassword"). HTML ("<font color= ' red ' > Password cannot be empty!) </font> ");
return false;
}
return true;
}
</script>