Created
October 25, 2014 16:51
-
-
Save DanWebProject/223f52ffcf24dd279eff to your computer and use it in GitHub Desktop.
can't get validation text to appear on error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title> validationform</title> | |
<style type="text/css"> | |
#invalid_1{ | |
color:red; | |
position:absolute; | |
top: 0px; | |
left :285px; | |
} | |
#invalid_2{ | |
color:red; | |
position:absolute; | |
top: 23px; | |
left: 285px; | |
} | |
#invalid_3{ | |
color:red; | |
position:absolute; | |
top: 45px; | |
left:285px; | |
} | |
</style> | |
<body> | |
<form name="myForm" action="mailto:[email protected]" method="post" onsubmit="return validation()"> | |
<fieldset> | |
Name: <input type="text" size="20" maxlength="12" id="name"/ ><br/> | |
Email: <input type="text" size="20" maxlength="12" id="email"/ ><br/> | |
Password: <input type="password" size="20" maxlength="12" id="password" /><br/> | |
<input type="submit" value="submit" /> <input type="reset" /> | |
</fieldset> | |
</form> | |
<p id="invalid_1"></p> | |
<p id="invalid_2"> Invalid email</p> | |
<p id="invalid_3"> Password must contain one upper case and one lower case</p> | |
<script type="text/javascript"> | |
var invalid = 0; | |
var i =0; | |
var j =0; | |
var k =0; | |
var length = document.getElementById("password").innerHTML ="invalid Email"; | |
function validateForm(){ | |
invalid = 0; | |
length = document.getElementById("password").value.length; | |
//name of user | |
if (document.getElementById("name").value == "") { | |
document.getElementById("invalid_1").innerHTML = "You must type in a name"; | |
invalid += 0; | |
} | |
else (document.getElementById("name").value == ""){ | |
document.getElementById("invalid_1").innerHTML = ""; | |
} | |
if (invalid != 0) { | |
return false; | |
} | |
else{ | |
return true; | |
} | |
if(document.getElementById("name").value.index("@")) == -1) { | |
document.getElementById("invalid_2").innerHTML = "Invalid Email"; | |
invalid += 1; | |
} | |
else { | |
document.getElementById("password").innerHTML ="invalid Email"; | |
} | |
//password checked | |
while (i < length) { | |
compare= document.getElementById("password").value.charAt(i).toUpperCase(); | |
if document.getElementById("password").value.charAt(i) != compare) { | |
j = 0; | |
while (j < length) { | |
compare= document.getElementById("password").value.charAt(j).toLowerCase(); | |
if (document.getElementById("password").value.charAt(j).!= compare) | |
document.getElementById("invalid_3").innerHTML = ""; | |
k=0; | |
} | |
else if (j == length -1) && (k == 0) { | |
document.getElementById("invalid_3")innerHTML = "Password must contain one upper case and one lower case"; | |
invalid +=1; | |
} | |
j++; | |
} | |
else if (i == length -1) && (k == 0) { | |
document.getElementById("invalid_3")innerHTML = "Password must contain one upper case and one lower case"; | |
invalid +=1; | |
} | |
i++; | |
} | |
//final validation | |
if (invalid != 0) { | |
return flase; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
help can't get validation text (Red) to appear on error after clicking submit help please!