Mike wrote on 30 Nov 2003:
<html>
<head>
<title>Test Page 01</title>
<META http-equiv="Content-Script-Type"
content="text/javascript"> <script type="text/javascript">
function checkPw(element) {
pw1 = document.forms['FormName'].elements['pw1'].value;
pw2 = element.value;
if (pw1 != pw2) {
window.alert ("Passwords do not match. Please
re-enter."); document.FormName.pw1.value="";
window.alert ("Please enter a password.");
document.FormName.pw2.value="";
window.alert ("Please re-enter your password.");
document.FormName.pw1.focus();
}
// -->
</script>
</head>
<body>
<form action="http://www.photoshelf.net/cgi-bin/mailto"
onsubmit="return FrontPage_Form1_Validator(this)" method="post"
name="FormName">
<input type="text" name="UserName" size="20" maxlength="60">
<input type="password" name="pw1" size="20" maxlength="60">
<input type="password" name="pw2" size="20" maxlength="60"
"this.value"><br>
<input type="submit" value="Submit Application"
onSubmit="if(this.value == 'Continue') this.form.submit();">
</body>
</html>
If this is exactly what you are testing, it's because the function
(used in the form onsubmit event) FrontPage_Form1_Validator() doesn't
exist.
You should remove the closing SGML comment (// -->) at the end of the
script block.
Finally, you should remove the onsubmit event on the submit button.
INPUT elements (of any type) don't have such an event, so it means
and does nothing.
Here's some advice to help you do the other things you asked about in
your original post:
You've already got the maximum lengths restricted in your HTML. To
set a minimum length, use [control reference].value.length. For
example:
document.forms['FormName'].elements['pw1'].value.length
To disable the submit button, place the following at the end of the
validation script so it will be executed when the form validates
correctly:
document.forms['FormName'].elements['submitButtonName'].disabled =
true;
If you make all these changes and add a proper onsubmit event handler
for the form, your document above would look something like:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Script-Type" content="text/javascript">
<TITLE>Test Page 01</TITLE>
<SCRIPT type="text/javascript">
function checkPw(form) {
var pw1 = form.elements['pw1'];
var pw2 = form.elements['pw2'];
var minPasswordLength = 6;
// Check password length
if ((minPasswordLength > pw1.value.length)
|| (minPasswordLength > pw2.value.length)) {
window.alert(
'Passwords must be at least ' + minPasswordLength
+ ' characters long.');
pw1.focus();
return false;
}
// Check password match
if (pw1.value != pw2.value) {
window.alert(
'The passwords do not match. Please re-enter.');
pw1.value = '';
pw2.value = '';
pw1.focus();
return false;
}
// By now, the passwords have been validated. The form can be
// submitted, and the submit button (I've named it 'apply'
// for this example) can be disabled.
form.elements['apply'].disabled = true;
return true;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="FormName" method="post"
action="http://www.photoshelf.net/cgi-bin/mailto"
onsubmit="return checkPw(this)">
<INPUT type="text" name="UserName" size="20" maxlength="60">
<INPUT type="password" name="pw1" size="20" maxlength="60">
<INPUT type="password" name="pw2" size="20" maxlength="60">
<INPUT type="submit" name="apply" value="Submit Application">
</BODY>
</HTML>
Hope this helps,
Mike
Sorry, I didn't mean to write this for you, but there were quite a
few mistakes creeping in that would take too much explanation to fix.
I think I was giving you too much new information without explaining
it properly. My fault.
--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)