/    Sign up×
Community /Pin to ProfileBookmark

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

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@CharlesMay 07.2003 — [font=monospace]<!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>[/font]
×

Success!

Help @Tasmanian_Devil spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...