Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ending a function... 1

Status
Not open for further replies.

BFreshour

Programmer
Mar 20, 2002
84
If I'm testing the value of my form with the following javascript, it pops up messages for each field that has no data. I would like it to exit the function IF the value is false which would only allow a max of one messagebox. Make sense?

Code:
function validate() {

	LCv=login.ClientID.value;
	if (LCv=='') {
	alert('You must select your company!');
	event.returnValue=false;
	}

	LUv=login.Username.value;
	if (LUv=='') {
	alert('You must enter a username!');
	event.returnValue=false;
	}

	LPv=login.Password.value;
	if (LPv=='') {
	alert('You must enter a password!');
	event.returnValue=false;
	}

}
 
try this:

function validate() {

LCv=login.ClientID.value;
if (LCv=='') {
alert('You must select your company!');
event.returnValue=false;
return;
}

LUv=login.Username.value;
if (LUv=='') {
alert('You must enter a username!');
event.returnValue=false;
return;
}

LPv=login.Password.value;
if (LPv=='') {
alert('You must enter a password!');
event.returnValue=false;
return;
}

}
 
bleh! I knew that. Sorry for bugging you! Thanks for your help...
 
here is a version that will work in more browsers and focus on the element the error was called on :

function validate()
{
if (document.login.ClientID.value == '')
{
alert('You must select your company!');
document.logic.ClientID.focus();
return false;
}

if (document.login.Username.value == '')
{
alert('You must enter a username!');
document.login.Username.focus();
return false;
}

if (document.login.Password.value == '')
{
alert('You must enter a password!');
document.login.Password.focus();
return false;
}
} Gary Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top