SitePoint Sponsor

User Tag List

Results 1 to 1 of 1

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    if else block is not working logically

    Hi,
    The following code fragment is bothering me way too much because it is running in a nonsensical fashion:
    Code:
    function popup(url, name, offset, modal) {
    ...
    for(i = 0; i < pl; i++) {
          if(pw[i].closed)
              continue;
          if(pw[i].name.equals(name))
              break;
      }
    
      if(i == pl) {
          pw[i] = window.open(url, name, "toolbar=no, menubar=no, copyhistory=no, location=no, scrollbars=yes"
    	      + ", screenX=" + x + ", screenY=" + y
     	      + ", top=" + y + ", left=" + x
    	      + ", width=" + width + ", height=" + height);
          alert ("i: "+i+"\npl: "+pl+"\ni == pl ? "+(i == pl));
          pl++;
      }
      else if(pw[i].closed) {
          pw[i] = window.open(url, name, "toolbar=no, menubar=no, copyhistory=no, location=no, scrollbars=yes"
    	      + ", screenX=" + x + ", screenY=" + y
     	      + ", top=" + y + ", left=" + x
    	      + ", width=" + width + ", height=" + height);
      }
    }
    As you have guessed this is the code for generating popup. Problem happens only with firefox and when a user double clicks the link corresponding to the popup.

    The alert that is generated is completely weird. Double click causes to open 2 popups. For the first popup the output is shown in aberration.jpg. The output is ok. For the second popup the output is shown in aberration1.jpg. Here lies the problem. As you see from the code the alert is only shown when entering the first branch:
    Code:
    if (i == pl)
    so according to common sense when i and pl are equal then the execution would enter the if block and print the alert. But the output is showing that i = 0 and pl = 1 and i == poplen ? false.
    (pl is poplen in the image)

    How is this possible? if i != pl how can
    Code:
    if (i == pl)
    return true and the enter into the block?

    Please help here. wasting too much time here.

    Attachments:
    aberration.JPG

    aberration1.JPG
    Last edited by ashim; Sep 17, 2007 at 21:06.


Bookmarks

Posting Permissions

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