Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    Southern California
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Strange JavaScript bug???

    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?

    Code:
      <SCRIPT LANGUAGE="JavaScript">
            <!--
            theURL=location.href;
            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">');
            }
            // -->
        </SCRIPT>
    Everyone has the right to be stupid, some just abuse the privilege.

  • #2
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Location
    Southern California
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are absolutely correct. I was looking at it backwards...
    Everyone has the right to be stupid, some just abuse the privilege.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •