[thelist] Javascript problem

Lachlan Cannon tiedefenderdelta6 at yahoo.com
Mon Dec 3 09:14:39 CST 2001


Hey everyone,

After staring at this for an hour trying to figure out what
was wrong, I throw myself at your mercy... or
javascriptliness or whatever it's called.

I'm trying to set up my own web based mail system (for
kicks and because I can), and I'm working on the client
side half at the moment. I'm using the following function
to make sure all the necessary fields are filled in,
correctly (or as correctly as I can figure out how to check
for), yet for some reason if the to field is filled in,
even if it doesn't meet the rules and nothing else does it
still submits the form.

function checkMail() {
var errors="";
var errorstart="Please make sure you have completed the
e-mail form correctly.\n The following errors were
detected:\n\n";
var
emailto=document.forms["mailform"].elements["emailto"].value;
var
subject=document.forms["mailform"].elements["subject"].value;
var body=document.forms["mailform"].elements["body"].value;
if (emailto == ""){
	errors+="You must supply an address in the \'to\'
field.\n";
}
else if (emailto.indexof('@') == -1 || emailto.indexof('.')
== -1) {
	errors+="You must supply only valid e-mail addresses.\n";
}
if (subject == "") {
	errors+="You must supply a subject.\n"
}
if (body == "") {
	errors+="You must supply a message to send.\n";
}
if (errors != "") {
alert (errorstart+errors);
return false;
}
else {
return true;
}
}

Oh, and improvements to the email checking are welcome too.
;)

TIA,

Lachlan Cannon
{Luminosity}

__________________________________________________
Do You Yahoo!?
Buy the perfect holiday gifts at Yahoo! Shopping.
http://shopping.yahoo.com




More information about the thelist mailing list