/    Sign up×
Community /Pin to ProfileBookmark

Return (True) vs Return (False)

Man, I’m sorry to be such a pain in the butt on this board. When I finally figure stuff out, I promise to give back and stick around and answer questions!

Here is my problem:

When I run this code:

[code]
function fieldValidation()
{
var result=true; // Return Value

alert(“Test 1 – Made it this far!”);

CheckAccount();
CheckPatient();

alert(“Last Test!”);
}
function CheckAccount()
{
alert(“Test 3 – Made it this far!”);
}
function CheckPatient()
{
if (cc_form.PTLName.value == “”)
{
alert(“Please enter patient LAST NAME.”);
cc_form.PTLName.focus();
return (false);
}
}
[/code]

It prints:
“Test 1 – Made it this far!”
“Test 3 – Made it this far!”
“Please enter patient LAST NAME”
“Last Test!”

I’m not sure exactly how to do this. But is there a way to make the function STOP, or a QUIT, if the first condition is met?

Like basically, as you can see above, the function “CheckPatient”. Is there a way that I can say like…

If CheckPatient = FALSE Then QUIT?

I don’t want it to print “Last Test!”, if the condition in CheckPatient is not met.

Anyone have any idea?

And like I said, when I’ve got this whole thing figured out, I promise to stick around and help answer questions to other newbies in my current situation!!!

Thanks!!!

Todd

to post a comment
JavaScript

13 Comments(s)

Copy linkTweet thisAlerts:
@Todd82TAauthorAug 24.2005 — Ok, quick addendum to this.

I figured out that I could do it like this:

<i>
</i>if (result=true) { return(false)} else { return(true)}


I basically did this a million times before, but this time it worked???

Anyway, now my problem is, how can I set result from within another function? I guess my question now is... how can I retrieve the result of a function, from within a function?


Using my code above in the first post in this thread, how would I do something like this:


<i>
</i>result=CheckAccount()


And how do I SET the result of CheckAccount() while I'm IN that function?


Thanks... :
Copy linkTweet thisAlerts:
@BigMoosieAug 24.2005 — The [I]return[/I] operator (not function) will quit a function when parsed and send whatever is on the right hand side as the result, if there is nothing on the right then undefined is sent. I'm not quite sure where you are confused, so just run this and maby it will clear things up:

function moose(cond){
if (cond) return "hello";
return "goodbye";
}

alert(moose(true));
alert(moose(false));
Copy linkTweet thisAlerts:
@Todd82TAauthorAug 24.2005 — Thank You!!!!!!!!!!!!!!!!!!!!!!!!!!
Copy linkTweet thisAlerts:
@Todd82TAauthorAug 24.2005 — Hi, I did what you said... I am totally going insane. I don't know why this is so hard for me to grasp.

I've only had 3 days exposure to any kind of Java or Java Scripting, but I'm still totally confused!!!!!!!!!!!! AHHHHHHHHHHHHHHHH!!!


This is my code now:

<i>
</i>function fieldValidation()
{
alert("YOU SHOULD SEE THIS FIRST");

if (CheckPatient(true))
{ alert("IF FIELD IS BLANK, YOU SHOULD SEE THIS")
return (false);
}

alert("THIS SHOULD PRINT IF THE FIELD IS NOT BLANK");
}



function CheckPatient()
{
if (cc_form.PTLName.value == "")
{ return (true);
cc_form.PTLName.focus();
}
return (false);
}



All that I want it to do is basically this:


I want it to check the field PTLName. If the field is BLANK, I want it to return a false (and set the focus). When it's false, it should NOT print the last line in the function which says "THIS SHOULD PRINT IF THE FIELD IS NOT BLANK".

The reason why I'm doing this is because I want to have multiple ones.

I just can't understand why this is so hard for me to understand.


The example you gave me was:

<i>
</i>function moose(cond) {
if (cond) return "Hello";
return "goodbye";
}

alert (moose(true));
alert (moose(false));



What my code is doing is displaying the first two alerts, regardless of whether or not the field is empty or filled. !!!


Any help is appreciated...

Thanks! ?
Copy linkTweet thisAlerts:
@Todd82TAauthorAug 24.2005 — AHHHHHHHHHHHHHHHHH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


How can I return a variable from a function? Is Javascripting like an actual language? or is it very limited? It seems like there's very little that I can do? either that or I just don't understand the syntax. I'm going completely crazy. I don't know what to do!! I've never had so much difficulty understanding something that seems to come so easily to everyone else.


This is what I want to do:

1 - I've got a blank field. I want to validate whether or not it's blank.

2 - If it's blank, I want it to go back to the page and not do anything.

3 - If it's filled, I want it to check the NEXT field.

4 - If that field is filled and there's no problem, then I want it to go to the next one, and so forth.

This code has changed around so much, that I'm totally confused.


THIS is my big question here....

HOW can I assign the RETURN VALUE of a function, to a variable?

In any other language, I've always been able to do things like...


Variable1 = Function()


How do I do that?
Copy linkTweet thisAlerts:
@Todd82TAauthorAug 24.2005 — I will PayPal someone $5 bucks if you can figure this F**KING CRAP OUT FOR ME!!!


Why does this crap not work? It doesn't even RUN now...

it should be pretty easy to figure out what it is that I'm trying to accomplish from this code:
<i>
</i>function fieldValidation()
{
alert ("!!! THIS SHOULD ALWAYS PRINT !!!");

If CheckAccount(false) {return (false)};

alert ("THIS SHOULD ONLY PRINT IF CheckAccount = TRUE");

}

function CheckAccount()
{
if (cc_form.PTLName.value == "")
{
alert ("THIS SHOULD PRINT IF ACCOUNT IS FALSE!!!");
return (true);
}
else
{
return (false);
}
}
Copy linkTweet thisAlerts:
@GuaranaAug 24.2005 — This should do... Keep your money and get yourself a JS book ?

function fieldValidation(){

alert ("!!! THIS SHOULD ALWAYS PRINT !!!");

if (CheckAccount())

{

return false;

}

alert ("THIS SHOULD ONLY PRINT IF CheckAccount = TRUE");

}

function CheckAccount() {

if (cc_form.PTLName.value == "") {

alert ("THIS SHOULD PRINT IF ACCOUNT IS FALSE!!!");

return true;

} else {

return false;

}

}
Copy linkTweet thisAlerts:
@Todd82TAauthorAug 24.2005 — Ok man... send me your PayPal address, I'll send you over $5... it worked!


Thanks! heheh...
Copy linkTweet thisAlerts:
@Todd82TAauthorAug 24.2005 — Crap, it's still not working....

When I run the code that you give me... EVEN if the field has data entered into it, it still does it.



?
Copy linkTweet thisAlerts:
@GuaranaAug 24.2005 — Then your field is realy empty... Try this:

function CheckAccount() {

if (cc_form.PTLName.value == "") {

alert ("cc_form.PTLName.value = '"+cc_form.PTLName.value+"'" );

return true;

} else {

return false;

}

}

If it return {cc_form.PTLName.value = '') then your field is really empty ?
Copy linkTweet thisAlerts:
@Todd82TAauthorAug 24.2005 — No, your first response worked....

I'm sorry,

I'm being totally lame, emotional, and all that other crap.

Thanks for the help!
Copy linkTweet thisAlerts:
@GuaranaAug 24.2005 — No problem ?
Copy linkTweet thisAlerts:
@Todd82TAauthorAug 24.2005 — Yeah, I appreciate it.


It looks like formatting and getting everything just right is very KEY when it comes to Java scripting.

It's working like a champ now.


<i>
</i>function fieldValidation()
{
alert ("!!! START FIELD VALIDATION !!!");

if (CheckAccount())
{
return false;
}

if (CheckPatient())
{
return false;
}

if (CheckCreditCard())
{
return false;
}

if (CheckAddress())
{
return false;
}

alert ("PROCESS BILLING!!!");
}






// --- ACCOUNT ENTRY INFORMATION CHECK ---
function CheckAccount() {
if (cc_form.Account.value == "")
{
alert ("The 1st field of your account number was left blank.n **Please enter your account number.");
cc_form.Account.focus();
return true;
}

if (cc_form.groupno.value == "")
{
alert ("The 2nd field of your account number was left blank.n **Please enter your account number.");
cc_form.groupno.focus();
return true;
}

if (cc_form.billarea.value == "")
{
alert ("The 3rd field of your account number was left blank.n **Please enter your account number.");
cc_form.billarea.focus();
return true;
}
else
{
return false;
}
}





// --- PATIENT ENTRY INFORMATION CHECK ---
function CheckPatient() {
if (cc_form.PTLName.value == "")
{
alert ("The LAST NAME field was left blank.n **Please enter your last name.");
cc_form.PTLName.focus();
return true;
}

if (cc_form.PTFName.value == "")
{
alert ("The FIRST NAME field was left blank.n ****Please enter your last name.");
cc_form.PTFName.focus();
return true;
}

if (cc_form.email.value == "")
{
alert ("The EMAIL field was left blank.n **Please enter your last name.");
cc_form.email.focus();
return true;
}
else
{
return false;
}
}




// --- CREDIT CARD ENTRY INFORMATION CHECK ---
function CheckCreditCard() {
if (cc_form.Number.value == "")
{
alert ("Credit Card number is blank.n*Please enter your credit card number.");
cc_form.Number.focus();
return true;
}

if (cc_form.ccname.value == "")
{
alert ("***The LAST NAME field for your credit card was left blank.n Please enter your last name as it is shown on your card.");
cc_form.ccname.focus();
return true;
}

if (cc_form.ccname_1.value == "")
{
alert ("***The FIRST NAME field for your credit card was left blank.n Please enter your first name as it is shown on your card.");
cc_form.ccname_1.focus();
return true;
}

if (cc_form.Amount.value == "")
{
alert ("***The AMOUNT field for your credit card was left blank.n Please enter the amount you wish to have charged.");
cc_form.Amount.focus();
return true;
}
else
{
return false;
}
}




// --- BILLING ADDRESS ENTRY INFORMATION CHECK ---
function CheckAddress() {
if (cc_form.ccadd1.value == "")
{
alert ("Billing ADDRESS was left blank.n*Please enter your current billing address.");
cc_form.ccadd1.focus();
return true;
}

if (cc_form.cccity.value == "")
{
alert ("The billing CITY field was left blank.n Please enter the current city for your billing address.");
cc_form.cccity.focus();
return true;
}

if (cc_form.cccountry.value == "")
{
alert ("The billing COUNTRY field was left blank.n Please enter the country for your current billing address.");
cc_form.cccountry.focus();
return true;
}

if (cc_form.cczip.value == "")
{
alert ("The billing ZIP CODE field was left blank.n Please enter a valid ZIP CODE for your billing address.");
cc_form.cczip.focus();
return true;
}
else
{
return false;
}
}



Now I've got to try to teach myself Java in the next couple of days (is that even possible?) and then access an applet which accesses a database and validates the data.



Thanks!!!

Todd
×

Success!

Help @Todd82TA spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...