Str comparison tests true in IE; false in Mozilla/Netscape

T

The Master

As the subject states, I'm having issues with if else statements that
are testing true in IE but false in Mozilla. At first I Thought maybe
the way I was splitting the string was leaving trailing white spaces
in Mozilla, but that was not the case (as the alert in the else
statement shows). So I'm at a complete loss here. The reason for this
script is to make the button mouse overs to remain active on their
respective pages, without having to hard code it on each respective
page. The reason is because the buttons are in an include file (which
is a temp fix until we get the whole site running on a database).

Here is the code (for whatever reason Mozila only runs the alert in
the else statement.):

function PageName() {
var NextPage = new String(location.href);
var ArrNextPage = NextPage.split("/");
var NextPage2 = new String(ArrNextPage[eval(ArrNextPage.length -
1)]);
var ArrNextPage2 = NextPage2.split(".");
var NextPage3 = new String(ArrNextPage2[0]);

if (NextPage3 == "massage") {
VV_swapImage('massage','','./images/massageOver.jpg',1);
VV_changeProp('navChange','','src','./images/navChangeOver.jpg','IMG');
VV_showHideLayers('massageLink','','show');

} else if (NextPage3 == "ballFitness") {
VV_swapImage('ballFitness','','./images/ballFitnessOver.jpg',1);
VV_changeProp('navChange','','src','./images/navChangeOver.jpg','IMG');
VV_showHideLayers('ballFitnessLink','','show');

} else if (NextPage3 == "bellydance") {
VV_swapImage('bellydance','','./images/bellydanceOver.jpg',1);
VV_changeProp('navChange','','src','./images/navChangeOver.jpg','IMG');
VV_showHideLayers('bellydanceLink','','show');

} else if (NextPage3 == "danceFitness") {
VV_swapImage('dance','','./images/danceOver.jpg',1);
VV_changeProp('navChange','','src','./images/navChangeOver.jpg','IMG');
VV_showHideLayers('danceFitnessLink','','show');

} else if (NextPage3 == "yoga") {
VV_swapImage('yoga','','./images/yogaOver.jpg',1);
VV_changeProp('navChange','','src','./images/navChangeOver.jpg','IMG');
VV_showHideLayers('yogaLink','','show');

} else if (NextPage3 == "wellness") {
VV_swapImage('taiChi','','./images/taiChiOver.jpg',1);
VV_changeProp('navChange','','src','./images/navChangeOver.jpg','IMG');
VV_showHideLayers('taiChiLink','','show');

} else if (NextPage3 == "pilates") {
VV_swapImage('pilates','','./images/pilatesOver.jpg',1);
VV_changeProp('navChange','','src','./images/navChangeOver.jpg','IMG');
VV_showHideLayers('pilatesLink','','show');

} else if (NextPage3 == "transform") {
VV_swapImage('fitness','','./images/fitnessOver.jpg',1);
VV_changeProp('navChange','','src','./images/navChangeOver.jpg','IMG');
VV_showHideLayers('fitnessLink','','show');

} else if (NextPage3 == "pregnancyFitness") {
VV_swapImage('pregnancy','','./images/pregnancyOver.jpg',1);
VV_changeProp('navChange','','src','./images/navChangeOver.jpg','IMG');
VV_showHideLayers('pregnancyLink','','show');

} else if (NextPage3 == "relaxation") {
VV_swapImage('relaxation','','./images/relaxationOver.jpg',1);
VV_changeProp('navChange','','src','./images/navChangeOver.jpg','IMG');
VV_showHideLayers('relaxationLink','','show');

} else if (NextPage3 == "backcare") {
VV_swapImage('backcare','','./images/backcareOver.jpg',1);
VV_changeProp('navChange','','src','./images/navChangeOver.jpg','IMG');
VV_showHideLayers('backcareLink','','show');
} else {
alert('3' + NextPage3 + '3');
}
}
 
D

Douglas Crockford

The said:
As the subject states, I'm having issues with if else statements that
are testing true in IE but false in Mozilla. At first I Thought maybe
the way I was splitting the string was leaving trailing white spaces
in Mozilla, but that was not the case (as the alert in the else
statement shows). So I'm at a complete loss here. The reason for this
script is to make the button mouse overs to remain active on their
respective pages, without having to hard code it on each respective
page. The reason is because the buttons are in an include file (which
is a temp fix until we get the whole site running on a database).

Here is the code (for whatever reason Mozila only runs the alert in
the else statement.):

function PageName() {
var NextPage = new String(location.href);
var ArrNextPage = NextPage.split("/");
var NextPage2 = new String(ArrNextPage[eval(ArrNextPage.length -
1)]);
var ArrNextPage2 = NextPage2.split(".");
var NextPage3 = new String(ArrNextPage2[0]);

There are two suspicious things here. First, don't use the String constructor.
This isn't Java. You never have to say
new String(...)
Strangely, the String constructor makes an object, not a string. Get rid of it.
Second, you are using eval(), which is strictly for the tards. Clean it up and
try again.

http://www.ecmascript.net/
 
M

MikeB

The Master said:
As the subject states, I'm having issues with if else statements that
are testing true in IE but false in Mozilla. At first I Thought maybe
the way I was splitting the string was leaving trailing white spaces
in Mozilla, but that was not the case (as the alert in the else
statement shows). So I'm at a complete loss here. The reason for this
script is to make the button mouse overs to remain active on their
respective pages, without having to hard code it on each respective
page. The reason is because the buttons are in an include file (which
is a temp fix until we get the whole site running on a database).

Here is the code (for whatever reason Mozila only runs the alert in
the else statement.):

function PageName() {
var NextPage = new String(location.href);
var ArrNextPage = NextPage.split("/");
var NextPage2 = new String(ArrNextPage[eval(ArrNextPage.length -
1)]);
var ArrNextPage2 = NextPage2.split(".");
var NextPage3 = new String(ArrNextPage2[0]);

if (NextPage3 == "massage") {

maybe: NextPage3.toLowerCase() // just in case the href is mixed or uppercase
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen
in news:comp.lang.javascript said:
As the subject states, I'm having issues with if else statements that
are testing true in IE but false in Mozilla. At first I Thought maybe
the way I was splitting the string was leaving trailing white spaces
in Mozilla, but that was not the case (as the alert in the else
statement shows). So I'm at a complete loss here. The reason for this
script is to make the button mouse overs to remain active on their
respective pages, without having to hard code it on each respective
page. The reason is because the buttons are in an include file (which
is a temp fix until we get the whole site running on a database).

Simplify before posting. Almost certainly. the problem remains with
only two cases; and with alert(number) instead of VV triplets. If it
does not, that's valuable evidence.

For test, show the value of NextPage3 before testing it; it may well not
be what you think it is.

Your function appears to depend only on location.href; that should, for
easier testing, be a parameter.

Your eval() is superfluous. Your new String() are superfluous.

NextPage3 could more briefly be extracted by a RegExp; a RegExp expert
should be here shortly. The following gives 'frequent', and may be
right :
S = "C:/HOMEPAGE/frequent.htm"
S = S.match(/\/([^\/]*)(\..*)/)[1] // .toLowerCase()

The code might be neater using a switch

switch (NextPage3) {
case "massage" : { VV() ; VV() ; VV() }
case ...
...
default : : {...} }

Since the VV triplets are so repetitive, replace each triplet with a
single function call using three parameters, or even one.

Don't call yourself "The Master" until you deserve it; it has an effect
on your readers which you should not be wanting.
 
T

The Master

Thanks that fixed the issue for Netscape/Mozilla. Which makes me
currious as to why it now works for Netscape/mozilla? Also what is the
tards?

Do you know of a really good Javascript book that teaches the proper
syntax. Since I'm finding that every so often that javascript
exlpination online can tend to give you bad syntax examples.

Sincerely,
The Master
 
D

Douglas Crockford

There are two suspicious things here. First, don't use the
Thanks that fixed the issue for Netscape/Mozilla. Which makes me
currious as to why it now works for Netscape/mozilla? Also what is the
tards?

The standards on which The Web is based are the most faulty and least complied
with of all international technical standards. If you want your stuff to work on
a variety of browsers, you need to restrict yourself to those features which are
best specified and best complied with. jslint is a tool that can help you there:
http://www.crockford.com/javascript/lint.html
Do you know of a really good Javascript book that teaches the proper
syntax. Since I'm finding that every so often that javascript
exlpination online can tend to give you bad syntax examples.

Nearly all JavaScript books are quite awful. Recommendations on good ones can be
found here: http://www.crockford.com/javascript/javascript.html
 
T

The Master

NextPage3 could more briefly be extracted by a RegExp; a >RegExp expert
should be here shortly. The following >gives 'frequent', and may be
right :
S = "C:/HOMEPAGE/frequent.htm"
S = S.match(/\/([^\/]*)(\..*)/)[1] // .toLowerCase()
The code might be neater using a switch
switch (NextPage3) {
case "massage" : { VV() ; VV() ; VV() }
case ...
...
default : : {...} }
Since the VV triplets are so repetitive, replace each >triplet with a
single function call using three >parameters, or even one.

Thanks for the Tips.
Don't call yourself "The Master" until you deserve it; it >has an
effect on your readers which you should not be >wanting.

Come on don't tell me you haven't seen Dr Who. The Master was hardly a
genious as the good ole Dr always beat him.

Sincerely,
The Master
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,118
Latest member
LatishaWhy
Top