-
June 12th, 2011, 07:21 AM
#1
Undefinded problem...
Hello,
I have the following JavaScript:
Code:
var ev_index = "001";
if (ev_index == "001")
{
return "hello";
}
if the var ev_index does not = to 001 I want it to exit and not do anything.
at the minute it returns undefinded.
Does anyone know how to just exit the if statement without returning anything.
Thanks.
-
June 12th, 2011, 10:55 AM
#2
Re: Undefinded problem...
Only functions can return a value. You are looking for break.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
June 12th, 2011, 08:52 PM
#3
Re: Undefinded problem...
Hello,
I have now done the following:
Code:
var ev_index = "001";
if (ev_index == "001")
{
return "hello";
}
else
{
break;
}
If the ev_index = 001 it works fine
but, If the ev_index = any other number it comes up with a Syntax error. (invalid break statement)
Am I using the break correct ?
Aaron.
-
June 12th, 2011, 09:28 PM
#4
Re: Undefinded problem...
No. It is not correct. As I said in my previous post, you cannot use return in a in if() statement. Only functions have returns. Hence why you are getting an undefined return.
But, why even bother checking the positive if you only want to check for a negative? Save yourself some code.
Code:
if (ev_index != "001") {
// do processing here
}
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|