jquery verifies that the JSP page property is empty (instance code) _jquery

Source: Internet
Author: User

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>
&LT;TD width= "451" > </td>
&LT;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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.