Can someone help me out? I want this script to submit, and self close the window if the two passwords match and are longer than four characters. I have it to submit and close but not to stop if passwords do not match or are not four characters long. Here is what I got:
<head>
<SCRIPT LANGUAGE=”JavaScript”>
function validatePwd() {
var invalid = ” “; // Invalid character is a space
var minLength = 4; // Minimum length
var pw1 = document.myForm.password.value;
var pw2 = document.myForm.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.myForm.password.value.length < minLength) {
alert(‘Your password must be at least ‘ + minLength + ‘ characters long. Try again.’);
return false;
}
// check for spaces
if (document.myForm.password.value.indexOf(invalid) > -1) {
alert(“Sorry, spaces are not allowed.”);
return false;
}
else {
if (pw1 != pw2) {
alert (“You did not enter the same password twice. Please re-enter your password.”);
return false;
}
else {
alert(‘Thank you.’);
return true;
}
}
}
</script>
<body>
<input type=button onclick=”this.form.submit(); self.close()” value=”Submit”>
Thanks