dansajd
11-10-2003, 10:57 AM
I have a form in which I must accomplish three things before submission:
1. Field Validation
2. Email Address Confirmation
3. User must supply a name -or- a phone number of the person that referred them (for the sake of readability, I'll refer to this as "either/or" in this post).
I found three scripts from The JavaScript Source that meet my needs. As such, individually, I can accomplish all three items. The problem is, I can't seem to find a way to do all three at once.
I've read over numerous threads on combining onSubmit event handlers and have tried many different variations, but I keep coming up empty.
I'm not having any problems with field validation. This is being handled through an onClick event handler in the form. I can use either the Email Address Confirmation or the either/or script without an issue in combination with the field validation. I really need both to work.
Here are the individual scripts:
Email Confirmation (modified password confirmation script)
function validatePwd() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.join.From.value;
var pw2 = document.join.From2.value;
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your email address twice.');
return false;
}
// check for minimum length
if (document.join.From.value.length < minLength) {
alert('Your email address must be at least ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (document.join.From.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed in your email address.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same email address twice. Please re-enter your email address.");
return false;
}
}
}
Eiter/Or
function checkFields() {
name = document.submitform.name.value;
email = document.submitform.email.value;
if ((name == "") && (email == "") ) {
alert("Please enter your name or your email address.");
return false;
}
else return true;
}
I've tried adding:
onSubmit="return validatePwd(); return checkFields()"
onSubmit="return validatePwd(); checkFields()"
I've also tried combining both scripts into one:
function validatePwd() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.join.From.value;
var pw2 = document.join.From2.value;
var name = document.join.refername.value;
var email = document.join.referemail.value;
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your e-mail address twice.');
return false;
}
// check for minimum length
if (document.join.From.value.length < minLength) {
alert('Your e-mail address must be at least ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (document.join.From.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed in your e-mail address.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same e-mail address twice. Please re-enter your e-mail address.");
return false;
}
}
else {
if (name == '' && email == '') {
alert("Please enter the name or e-mail address of the person who referred you.");
return false;
}
}
}
This last one gets me the closest to accomplishing what I need it to do. The problem is that when I click on the "OK" button on the alert box, the form gets submitted anyway.
I am ridiculously lost. Can someone please help me figure out what I need to do to get both these scripts to work together?
I apologize if I left anything out and for the length of this post. Please let me know if you require further information.
1. Field Validation
2. Email Address Confirmation
3. User must supply a name -or- a phone number of the person that referred them (for the sake of readability, I'll refer to this as "either/or" in this post).
I found three scripts from The JavaScript Source that meet my needs. As such, individually, I can accomplish all three items. The problem is, I can't seem to find a way to do all three at once.
I've read over numerous threads on combining onSubmit event handlers and have tried many different variations, but I keep coming up empty.
I'm not having any problems with field validation. This is being handled through an onClick event handler in the form. I can use either the Email Address Confirmation or the either/or script without an issue in combination with the field validation. I really need both to work.
Here are the individual scripts:
Email Confirmation (modified password confirmation script)
function validatePwd() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.join.From.value;
var pw2 = document.join.From2.value;
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your email address twice.');
return false;
}
// check for minimum length
if (document.join.From.value.length < minLength) {
alert('Your email address must be at least ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (document.join.From.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed in your email address.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same email address twice. Please re-enter your email address.");
return false;
}
}
}
Eiter/Or
function checkFields() {
name = document.submitform.name.value;
email = document.submitform.email.value;
if ((name == "") && (email == "") ) {
alert("Please enter your name or your email address.");
return false;
}
else return true;
}
I've tried adding:
onSubmit="return validatePwd(); return checkFields()"
onSubmit="return validatePwd(); checkFields()"
I've also tried combining both scripts into one:
function validatePwd() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.join.From.value;
var pw2 = document.join.From2.value;
var name = document.join.refername.value;
var email = document.join.referemail.value;
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your e-mail address twice.');
return false;
}
// check for minimum length
if (document.join.From.value.length < minLength) {
alert('Your e-mail address must be at least ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (document.join.From.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed in your e-mail address.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same e-mail address twice. Please re-enter your e-mail address.");
return false;
}
}
else {
if (name == '' && email == '') {
alert("Please enter the name or e-mail address of the person who referred you.");
return false;
}
}
}
This last one gets me the closest to accomplishing what I need it to do. The problem is that when I click on the "OK" button on the alert box, the form gets submitted anyway.
I am ridiculously lost. Can someone please help me figure out what I need to do to get both these scripts to work together?
I apologize if I left anything out and for the length of this post. Please let me know if you require further information.