lundi 29 décembre 2014

Enable checkbox only if fields are correctly filled [on hold]


I want that my check box should be enable only when all the fields are filled correctly and should not be empty.


This is registration form with JavaScript validation. I just want that the check box should be enable when all the fields are correctly filled.



<form name='frm'>
Firstname:<input type="text" name='fname' id="firstname" maxlength="50" onblur="validateformfirst()" />
<div id='firsterror' style="color:red"></div><BR>

Lastname:<input type="text" name='lname' id="lastname" maxlength="50" onblur="validateformlast()"/>
<div id='lasterror' style="color:red" ></div><br>

Email:<input type="text" name='email' id="email" maxlength="200" onblur="validateformemail()"/>
<div id='emailerror' style="color:red"></div><br>

Password:<input type="password" name='password' id="password" maxlength="100" onblur="validateformpassword()" onKeyUp="verify.check()"/>
<div id='passworderror' style="color:red"></div><br>

Confirm Password <input type="password" name='confirmpassword' id="confirmpassword" onKeyUp="verify.check()"/>
<div id='confirmpassworderror' style="color:red"></div><br>

<input type="checkbox" name="terms" id="signin" onClick="EnableRegister(this)" DISABLED="disable"/><span>I read Terms and Conditions</span>

<button type="submit" onclick=" validateForm()" id="Register" >Register</button>
</form>


and this is my javascript code which validate my form....can anyone combine this validation in such a way that...once all validate data is filled in the text box,,the checkbox should be enable...else it should be disable untill all filled correctly.



<script>
function validateformfirst(fname)
{
var str = true;
var charfilter = /^[a-zA-Z]*$/;
if (document.frm.fname.value == "") {
document.getElementById("firsterror").innerHTML = "Please enter FirstName";
str = false;
} else if (!charfilter.test(document.frm.fname.value)) {
document.getElementById("firsterror").innerHTML = "Please enter valid First Name";
str = false;
}
else{document.getElementById("firsterror").innerHTML = "";}
return str;
}

function validateformlast(lname)
{
var str = true;

var charfilter = /^[a-zA-Z]*$/;
if (document.frm.lname.value == "") {
document.getElementById("lasterror").innerHTML = "Please enter LastName";
str = false;
} else if (!charfilter.test(document.frm.lname.value)) {
document.getElementById("lasterror").innerHTML = "Please enter valid last Name";
str = false;
}
else{document.getElementById("lasterror").innerHTML = "";}
return str;
}

function validateformemail(email)
{
var str = true;

var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (document.frm.email.value == "") {
document.getElementById("emailerror").innerHTML = "Please enter email";
str = false;
} else if (!mailformat.test(document.frm.email.value)) {
document.getElementById("emailerror").innerHTML = "Please enter valid email";
str = false;
}
else{document.getElementById("emailerror").innerHTML = "";}
return str;
}



function validateformpassword(password)
{
var str = true;
var passwordformat=/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-_]).{8,}$/;
if (document.frm.password.value == "")
{
document.getElementById("passworderror").innerHTML = "Please enter password";
str = false;
} else if (!passwordformat.test(document.frm.password.value))
{
document.getElementById("passworderror").innerHTML = "Please enter valid password";
str = false;
}
else{document.getElementById("passworderror").innerHTML = "";}
return str;
}
</script>




Aucun commentaire:

Enregistrer un commentaire