View Full Version : Strange JavaScript bug???

10-24-2003, 02:05 AM
Been a while since I've posted here. :)

I have been playing with a simple boolean script. If a guest is viewing either one of teh 2 URL's listed in the if statement, they will not have the HTML table written out. if the guest is viewing a page other than the 2 listed they will get teh table written out. I figured I need the || (or) so if it's URL1 OR URL2 then don't write out the table. However it doesn't work, it only works if I use the && (and) which reads URL1 AND URL2, yet it works just like it was the OR boolean. Any insight as to why, or am I just completely off on this?

if (theURL.indexOf("cookbook.app?page=RecipeFinder") == -1 && theURL.indexOf("crafts?page=CraftDisplay") == -1)
document.write('<td width="37">&nbsp;</td>');
document.write('<td align="center" valign="top" width="125">');
document.write(' <table border="0" cellpadding="0" cellspacing="0" width="125">');
document.write(' <tr>');
document.write(' <td align="center" valign="top" width="125" height="605">');
document.write(' <table border="0" cellpadding="0" cellspacing="0" width="125">');
document.write(' <tr>');
document.write(' <td width="2">');
document.write(' <spacer type="block" height="1" width="2">');
document.write(' </td>');
document.write(' <td width="120" align="center">');
// -->

10-24-2003, 05:04 AM
if i understand you properly, then i think you've misunderstood the or operator. you want to display the table when BOTH pages aren't displayed; not when one or the other isn't being displayed. that's why you need the and operator; you want both (or really, neither, but it's the same thing in this case).

the or operator stops after the first true statement. so, if you're at the CraftDisplay page, then with the or operator, your script would check to see if you're at the RecipeFinder page, which you're not, so it's gonna go ahead and write the table out, because it's an either-or situation; if situation 1 has been met, it doesn't care about situation 2.

that came out a lot more convoluted than it is in my head, but hopefully, it made sense.

10-24-2003, 07:06 PM
You are absolutely correct. I was looking at it backwards... :eek: