Hi,
I have a user form that calls a javascript validation function. When I place the javascript in the page header it works perfectly, however when I move the script into an external .js file it stops working.
Can anyone see why its not calling the script correctly?
The form calls the script using:
onsubmit=”javascript:return validateInput(this);”
Header calls the script using:
<script language=”JavaScript” type=”text/javascript” src=”validate_user.js”></script>
The validate_user.js contains the following code:
function validateInput() {
// validate username
if (!document.createuser.username.value) {
alert(‘Please enter a username’); return false;
} else if (!document.createuser.fullname.value) {
alert(‘Please enter users full name’); return false;
} else if (!/^w+([.*@w+([..
alert(‘Invalid E-mail Address! Please re-enter.’); return false;
} else if (!document.createuser.company.value) {
alert(‘Please enter a company’); return false;
}
var invalid = ” “; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.createuser.password.value;
var pw2 = document.createuser.password2.value;
// check for a value in both fields.
if (pw1 == ” || pw2 == ”) {
alert(‘Please enter your password twice.’);
return false;
}
// check for minimum length
if (document.createuser.password.value.length < minLength) {
alert(‘Your password must be at least ‘ + minLength + ‘ characters long. Try again.’);
return false;
}
// check for spaces
if (document.createuser.password.value.indexOf(invalid) > -1) {
alert(‘Sorry, spaces are not allowed.’);
return false;
}
else {
if (pw1 != pw2) {
alert (‘You did not enter the same new password twice. Please re-enter your password.’);
return false;
}
else {
return true;
}
}
}
Thanks
Ben