Skip to content

Instantly share code, notes, and snippets.

@DanWebProject
Created October 25, 2014 16:51
Show Gist options
  • Save DanWebProject/223f52ffcf24dd279eff to your computer and use it in GitHub Desktop.
Save DanWebProject/223f52ffcf24dd279eff to your computer and use it in GitHub Desktop.
can't get validation text to appear on error
<!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:example@yahoo.com" 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;
}
//email
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>
@DanWebProject
Copy link
Author

help can't get validation text (Red) to appear on error after clicking submit help please!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment