Hey Jeremy,
The problem that I am running into for this lesson is that the code doesn't seem to want to work properly (isn't that always the problem? lol). The thing is when I bring up the Web developer toolbar it isn't showing any errors and it also shows that my scripts are linking to the html page properly, so I'm a little lost at the moment. Here is my HTML & script.
HTML:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lesson 28: Example 01</title>
</head>
<body>
<form name="theForm" action="" onsubmit="validateForm(event)">
<p>
Name: <input type="text" name="txtName">
</p>
<p>
Age: <input type="text" name="txtAge">
</p>
<p>
Email: <input type="text" name="txtEmail">
</p>
<p>
Password: <input type="password" name="txtPassword1">
</p>
<p>
Retype Password: <input type="password" name="txtPassword2">
</p>
<input name="btnSubmit" type="button" value="Submit">
</form>
<script src="eventUtility.js"></script>
<script src="script.js"></script>
</body>
</html>
and the Script:
Code:
function isEmpty(value) {
return (value === ""); //returns a boolean value
}
function validateForm(event) {
var theForm = document.theForm;
var txtName = theForm.txtName;
var txtAge = theForm.txtAge;
var txtEmail = theForm.txtEmail;
var txtPassword1 = theForm.txtPassword1;
var txtPassword2 = theForm.txtPassword2;
var button = theForm.btnSubmit;
var age = parseInt(txtAge.value, 10);
button.disabled = true;
//validate name field
if (!isEmpty(txtName.value)) {
//validate age
if (!isNaN(age) && age > 0) {
//validate Email field
if (txtEmail.value.indexOf("@") > 0) {
//validate password - pass 1
if (!isEmpty(txtPassword1.value)) {
//validate password - pass 2
if (txtPassword1.value === txtPassword2.value) {
return;
} else {
alert("Passwords do not match. Please reenter them.");
txtPassword1.focus();
txtPassword1.select();
}
} else {
alert("Password cannot be blank.");
txtPassword1.focus();
txtPassword1.select();
}
} else {
alert("Please enter a valid email address.");
txtEmail.focus();
txtEmail.select();
}
} else {
alert("Please enter your age,");
txtAge.focus();
txtAge.select();
}
} else {
alert("Please enter your name.");
txtName.focus();
}
button.disabled = false;
eventUtility.preventDefault(event);
}
Thanks again!