break out of JS function

by "Michael Gerholdt" <gerholdt(at)fredonia.edu>

 Date:  Thu, 12 Jul 2001 11:43:30 -0400
 To:  <hwg-techniques(at)hwg.org>
  todo: View Thread, Original
I have a form validation function that works nicely except it goes through
each field and pops up the alert.

I'd rather have it validate field by field, and only pop up the first alert.

It looks identical to another function that behaves as I want it, and so,
not being a JS guru, I'm mystified.

Here's a portion of the function. I would add the focus part to each section
after I get it working correctly.

TIA,
Mike

function validate() {

first=mainform.first.value;
if (first=='') {
alert('Your first name is a required field. Please try again.');
event.returnValue=false;
document.mainform.first.focus();
}

last=mainform.last.value;
if (last=='') {
alert('Your last name is a required field. Please try again.');
event.returnValue=false;
}

bldg=mainform.bldg.value;
if (bldg=='') {
alert('Your building is a required field. Please try again.');
event.returnValue=false;
}
}

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA