SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Mar 18, 2003, 19:56 #1
- Join Date
- Jan 2003
- Posts
- 32
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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(.....); } }
<a href="javascript:confirmPopUp()">Show Popup</a>
What am I doing wrong?
Thanks,
DoughBoy
-
Mar 18, 2003, 23:42 #2
- 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'); }
-
Mar 19, 2003, 00:05 #3
- 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); }
Code:function confirmReportCreation() { if (window.confirm("Are you sure you want to create the report?")) { openAnyWindow('createReportPDF.asp','Download',400,300); } }
Does it matter in what order the functions appear? I think I've changed the order, but to no avail.
-
Mar 19, 2003, 01:08 #4
- 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); } }
-
Mar 24, 2003, 00:05 #5
- 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