This is my HTML:
<html>
<head>
<title>Article</title>
<link rel="stylesheet" href="pop.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript" src="validator.js"></script>
<div id="comment_form">
<form method="POST">
Name:
<input type="text" name="name" id="name1" onblur="checkname()">
<br/> Email:
<input type="text" name="email" id="email1" onblur="checkemail()">
<br/>
<br/> Comment:
<br/>
<textarea name="comment" id="comment1" cols="50" rows="2" onblur="checkcomment()"></textarea>
<br/>
<input type="submit" value="comment" onsubmit="validateform()">
</form>
</body>
</html>
and this is my JavaScript:
function checkname() {
alert("Isee ur java script");
var myName = document.getElementById("name1");
var pos = myName.value.search(/^[A-Z][a-z] $/);
if (pos != 0) {
alert("Please Enter a Valid name. It should not contain numbers.");
retrun false;
} else
return true
}
function checkemail() {
var myEmail = document.getElementById("email1");
var pos = myEmail.value.search(/^[a-z]+-?\.?_?@[a-z]+\.[a-z]+$/);
if (pos != 0) {
alert("Please Enter a Valid Email Address. eg. [email protected]");
retrun false;
} else
return true
}
function checkcomment() {
var myComment = document.getElementById("comment1");
if (myComment == null || myComment == "") {
alert("Please add a comment.");
return false;
}
}
function validateform() {
if (myName == null || myName == "" || myEmail == null || myEmail == "" || myComment = null || myComment == "") {
alert("Please fill out all of the fields!");
}
}
It's not working at all, even if I try to alert something in one of the function it doesn't show up. I also tried adding this in validator.js instead of calling the events in HTML, and it's still not working.
document.getElementById("name").onblur = checkname;
document.getElementById("email").onblur = checkemail;
document.getElementById("comment").onblur = checkcomment;
myComment = nullat the end should bemyComment == null