PDA

View Full Version : javascript: return??



blah-de-blah
August 28th, 2003, 11:49 AM
ok third thread today...not doin too good with javascript :-\

So i was just wondering...why do you need to do return true or return false??

And sometimes its just:

return true

and other times its:

return (true)

is there a difference? Not too sure what the return thing is used for :-\ Never used it anything similiar in flash either :-\ Any help would be great thanks!!

Jubba
August 28th, 2003, 03:46 PM
you return true or false in order to do something. When you are validating a form you want to return true so the form gets processed or false so that the form doesn't go thru if there is a problem...

blah-de-blah
August 29th, 2003, 12:54 AM
Ah ok...since you're here i won't bother making a new thread :P Do you think you could explain this code from a email validation for me?



function isEmailAddr(email)
{
var result = false
var theStr = new String(email)
var index = theStr.indexOf("@");
if (index > 0)
{
var pindex = theStr.indexOf(".",index);
if ((pindex > index+1) && (theStr.length > pindex+1))
result = true;
}
return result;
}


I just don't understand:

if (index > 0)
{
var pindex = theStr.indexOf(".",index);
if ((pindex > index+1) && (theStr.length > pindex+1))
result = true;
}

that part (which is basically nearly the whole code :P). It is confusin me:-\ thanks

blah-de-blah
September 5th, 2003, 10:12 PM
:-\