SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Calling a Popup Menu Within a Function

    Hello,

    I must be really overlooking something here. I have a function called showPopUp() that works just fine when called from a link, such as:

    <a href="javascript:showPopUp(.....)">Show Popup</a>

    However, I would like to add a confirmation dialog box, like so:

    Code:
    function confirmPopUp()
    {
    	if (window.confirm("Are you sure you want to display the popup?"))
    	{	
    		showPopUp(.....);
    	}
    }
    However, the popup window doesn't appear if I change the link to:

    <a href="javascript:confirmPopUp()">Show Popup</a>

    What am I doing wrong?


    Thanks,


    DoughBoy

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Fort Lauderdale
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should work, there must be something small you are missing. Can you post all of your code?
    I made this:
    Code:
      function conf() {
    			if (window.confirm("sure?")) {
    				pop();
    			} else {
    				alert("hi");
    			}
    		}
    		function pop() {
    			self.open('test2.html');
    		}

    www.unpossiblemedia.com - A Fort Lauderdale based multimedia company.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    If it helps, here is the popup code I'm using (found on CNET):

    Code:
    function openAnyWindow(url, name) {
    
      // store number of arguments passed in
      var l = openAnyWindow.arguments.length;
    
      // initialize w (width)
      var w = "";
      // initialize h (height)
      var h = "";
      // initialize features (comma-delineated list of window features)
      var features = "";
    
      // loop through array of arguments to build list of features
      // begin loop with 2 (third element of array) to skip url and name
      for (i=2; i<l; i++) {
    
        // store current argument in variable param
        var param = openAnyWindow.arguments[i];
    
        // if param isn't a number, it's not width or height
        // in that case, append to features with comma
        if ( (parseInt(param) == 0) || (isNaN(parseInt(param))) ) {
          features += param + ',';
    
        // else param is a number; must be width or height
        } else {
    
          // if w hasn't been set yet, param must be the width
          // otherwise, w has been set, so param must be the height
          (w == "") ? w = "width=" + param + "," : h = "height=" + param;
        }
      }
    
      // append width and height strings to list of features
      features += w + h;
    
      // begin building statement to open window
      var code = "popupWin = window.open(url, name";
    
      // if l>2, there were more than two arguments
      // in that case, append comma, parenthesis, and list of features
      if (l > 2) code += ", '" + features;
    
      // finish building statement to open window
      code += "')";
    
      // execute statement to open window
      eval(code); 
    }
    And I call this routine from within another routine, which looks something like:

    Code:
    function confirmReportCreation()
    {
    	if (window.confirm("Are you sure you want to create the report?"))
    	{	
    		openAnyWindow('createReportPDF.asp','Download',400,300);
    	}
    }
    If you click "OK" when the confirmation dialog box appears, nothing happens.

    Does it matter in what order the functions appear? I think I've changed the order, but to no avail.

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Fort Lauderdale
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That code seems unnecessarily lengthy just to open a window. Here is my shortened version. It doesn't matter what order the functions are defined.
    Code:
    function openAnyWindow(url, name, w, h)
    {
      params = "width=" + w + ", height=" + h;
      self.open(url, name, params);
    }
    
    function confirmReportCreation()
    {
    	if (window.confirm("Are you sure you want to create the report?"))
    	{	
    		openAnyWindow('createReportPDF.asp','Download',400,300);
    	}
    }

    www.unpossiblemedia.com - A Fort Lauderdale based multimedia company.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just wanted to follow up.

    ::embarrassed:: My code wasn't working in the browser I normally use for development, which is Chimera for Mac OS X (similar to Phoenix for other platforms). When I tested it in IE Win, it worked fine.

    Oh, I think the reason the popup code seems overly complex is because it is flexible when it comes to adding attributes (scrollbars, left, top, location, etc.).


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
  •