jquery - Its not validating on my submit button click using javascript -


i have code in view

function validate() {    if (document.getelementbyid('mandatename').value == "") {         var err = document.getelementbyid('mandatenameerr');        err.innerhtml = "please enter value mandate name";        err.style.display = "block";        return false;    }    else {        document.getelementbyid('mandatenameerr').style.display = "none";    }     if (document.getelementbyid('mandatedescription').value == "") {        var err = document.getelementbyid('mandatedescriptionerr');        err.innerhtml = "please enter value mandate description";        err.style.display = "block";        return false;    }    else {        document.getelementbyid('mandatedescriptionerr').style.display = "none";    }     return true; } 

and have on submit button validating before submiting?

<button name="submit" onclick="validate()" >add variables mandate</button> 

i called validate function showing me if not entering on text box if click button showing me validation message same time going view , throwing me message?

even put return false; not working doing wrong?

you need put return in onclick, this:

<button name="submit" onclick="return validate()" >add variables mandate</button> 

otherwise you're executing validation...but not caring result.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -