By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Or Statement

P: n/a
I am implementing a conditional menu. The script below is evaluating
to see if I am on either of two specific pages. I have done it two
different way's and both are below.
Thanks in advance.

#1 This returns false all the time.

if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {
nacSecondary = true;
} else {
nacSecondary = false
};

#2 This returns true all the time.
if (pageName == 'nacPartnerPage' || 'networkAccessPage') {
nacSecondary = true;
} else {
nacSecondary = false
};
Jul 21 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
BillyZ <bi********@gmail.comwrote in news:449a2b9e-c3f5-4447-b323-
18**********@34g2000hsf.googlegroups.com:
I am implementing a conditional menu. The script below is evaluating
to see if I am on either of two specific pages. I have done it two
different way's and both are below.
Thanks in advance.

#1 This returns false all the time.

if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {
nacSecondary = true;
} else {
nacSecondary = false
};

#2 This returns true all the time.
if (pageName == 'nacPartnerPage' || 'networkAccessPage') {
nacSecondary = true;
} else {
nacSecondary = false
};
you need to be more explicit

if((pageName=='nacPartnerPage') || (pageName=='networkAccessPage')) {
//blah blah blah
}
Jul 21 '08 #2

P: n/a
On Jul 21, 4:48*pm, BillyZ <bill.za...@gmail.comwrote:
<snip>
#1 This returns false all the time.

if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {
<snip ^ ^

Unlikely. Without those two inner parentheses it might return false
all of the time. With them the above is equivalent to your second
attempt.

Jul 21 '08 #3

P: n/a
In article
<44**********************************@34g2000hsf.g ooglegroups.com>,
BillyZ <bi********@gmail.comwrote:
I am implementing a conditional menu. The script below is evaluating
to see if I am on either of two specific pages. I have done it two
different way's and both are below.
Thanks in advance.

#1 This returns false all the time.

if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {
This is not how you do an "or". You need to write:

if ((pageName=='nacPartnerPage') || (pageName=='networkAccessPage')) {
Jul 21 '08 #4

P: n/a
In comp.lang.javascript message <449a2b9e-c3f5-4447-b323-18f8aa2e763d@34
g2000hsf.googlegroups.com>, Mon, 21 Jul 2008 08:48:53, BillyZ
<bi********@gmail.composted:
>if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {
nacSecondary = true;
} else {
nacSecondary = false
};
Additionally, there is no need to write
if (A) B = true ; else B = false
which should be written
B = A
and is reversed by
B = !A

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 22 '08 #5

P: n/a
Tim Streater wrote:
BillyZ <bi********@gmail.comwrote:
>I am implementing a conditional menu. The script below is evaluating
to see if I am on either of two specific pages. I have done it two
different way's and both are below.
Thanks in advance.

#1 This returns false all the time.

if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {

This is not how you do an "or". You need to write:

if ((pageName=='nacPartnerPage') || (pageName=='networkAccessPage')) {
Another, less compatible possibility[1] is

if (pageName in {nacPartnerPage: 1, networkAccessPage: 1}) {

(provided one has not augmented Object.prototype).

But the `if' statement really is superfluous here:

nacSecondary = (one_of_the_suggested_boolean_expressions);
PointedEars
___________
[1] <http://PointedEars.de/es-matrix#i>
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Jul 22 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.