Validating a form on the client

Source: Internet
Author: User
When the client verifies the form, the submit button cannot be used to block the default event, and to prevent form submission, prevent the Sumint event from being committed on the form;
<!
    DOCTYPE html>  

/** * Created by Wenguang on 2015/12/4.
    */function Checkpassword () {//var Psw=document.getelementbyid (' PSW ');
    var Psw1=document.getelementbyid (' PSW1 ');
    var Test=document.getelementbyid (' Test2 ');
        if (psw.value!=psw1.value) {test.innerhtml= ' two times password inconsistent, please re-enter ';

return false} else return true;
    The function Checknotnull () {//Determines whether to be an empty var User=document.getelementbyid (' user ');
    var Psw=document.getelementbyid (' PSW ');
    var Psw1=document.getelementbyid (' PSW1 ');
        if (user.value== "") {var Span0=document.getelementbyid (' Test0 ');
        Span0.innerhtml= ' The item cannot be empty ';
    return false;
        else if (psw.value== "") {var Span1=document.getelementbyid (' test1 ');
        Span1.innerhtml= ' The item cannot be empty ';
    return false;
        else if (psw1.value== "") {var Span2=document.getelementbyid (' Test2 ');
        Span2.innerhtml= ' The item cannot be empty ';
    return false;
else return true;
}//Bound event function addevent (OBJ,TYPE,FN) {    if (Obj.addeventlistener) {Obj.addeventlistener (type,fn,false);
    }else if (obj.attachevent) {obj.attachevent (' on ' +type,fn); }//cross-browser block default behavior function Preventdefault (evt) {var e=evt| |
    window.event;
    if (E.preventdefault) {e.preventdefault ();
    }else{E.returnvalue=false;
    } addevent (window, ' Load ', function () {var Fm=document.getelementbyid (' register ');
        ADDEVENT (FM, ' Submit ', function (evt) {preventdefault (evt);
            if (Checknotnull ()) {if (Checkpassword ()) {//If two times the same password is submitted to Fm.submit ();
}
        }
    });

});
    addevent (window, ' Load ', function () {//Get focus is empty hint var user=document.getelementbyid (' user ');
    var Psw=document.getelementbyid (' PSW ');
    var Psw1=document.getelementbyid (' PSW1 ');
        Addevent (user, ' Focus ', function () {var Span0=document.getelementbyid (' Test0 ');
    Span0.innerhtml= ';
    }); Addevent (PSW, ' Focus ', function () {var Span1=document.getelEmentbyid (' test1 ');
    Span1.innerhtml= ';
    });
        Addevent (PSW1, ' Focus ', function () {var Span2=document.getelementbyid (' Test2 ');
    Span2.innerhtml= ';
});

 });

*{
    padding:0;
    margin:0;
}
body{
    background: #ccc;
    padding:0;
    margin:0;
    Color: #fff;
    font-family: "Microsoft ya hei Light";
}
#login {
    width:700px;
    Height:auto;
    margin:70px Auto;
    Background: #ddd;
}
#register div{
    width:700px;
    height:30px;
    Background: #030C1D;
    margin:2px 0;
    line-height:30px;;
}
. Form-div_1 input{
    width:200px;
    height:23px;
    margin-bottom:2px
}
. label_1{
    Display:inline-block;
    width:100px;
    Text-align:right
}
. Label_1 span{
    color:red;
}
#textArea {
    height:180px!important;
    line-height:200px;
}
#textArea textarea{
    display:inline;
    width:500px;
    height:160px;
    margin:10px 0;
}
#sub_reset input{
    margin-left:100px;
    width:100px;
    height:25px;
    Background: #3e3e3e;
    Color: #fff;
    font-size:20px;
}
#zhiYe {
    width:100px;
    height:23px;
}

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.