Jquery verifies whether the JSP page property is empty

Source: Internet
Author: User

Note: to verify whether the verification is null, you must first ensure that the verification is performed before the form is submitted. If there are empty items in the verification result, the form cannot be submitted and a verification error message is prompted, when the verification page property is not empty, the form is submitted normally. This part is a JS part and has nothing to do with the background business logic layer and control layer.
You can restrict the submission by using the form label or by adding the onclick event restriction on the submit button:
<Form action = ".." method = "Post"Onsubmit= "Return check ();">
<Input type = "Submit" value = "Submit"Onclick= "Return check ()">

Case:
<Form action = "./login. Action" method = "Post" onsubmit = "Return check ();">
<Table>
<Tr>
<TD width = "451"> & nbsp; </TD>
& Lt; TD width = "378" & gt;




User Name:








& nbsp;

& nbsp;
password:





& nbsp; & nbsp;

<! -- Introduce the JS file jquery -->
<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'> the user name cannot be blank! </Font> ");
Return false;
}
If (Password = ""){
$ ("# Checkpassword" ).html ("<font color = 'red'> the password cannot be blank! </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.