Click to See Complete Forum and Search --> : Help!!!


Tasmanian Devil
05-07-2003, 01:52 PM
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

Charles
05-07-2003, 01:58 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<form action="" onsubmit="if (this.first.value == this.second.value && /^\S{4}\S*$/.test(this.first.value)) {this.submit(); if (top.opener) top.close()} else {alert('Both \\'Password\\' fields must be the same, contain no spaces and be four or more characters in length.'); this.first.value=''; this.second.value=''}; return false">
<p><label>Password<br>
<input type="password" name="first"></label></p>
<p><label>Password<br>
<input type="password" name="second"></label></p>
<div><input type="submit"></div>
</form>