PDA

View Full Version : Passing variables into the external file path for DHTMLwindow



Bradley W. Schenck
08-04-2009, 03:01 AM
1) Script Title: Script: DHTML Window

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/index.htm

Hi, all. I've worked out how to create the windows I want, as far as style and features and position go.

Where I'm hitting the wall, though, is that I need to pass a couple of variables to the script because it may be called in different contexts. So for example I've edited the link to the function like this:


<a href="#" onClick="open_inventory(brain); return false">Open Window</a>

...and the function to this:


function open_inventory(invpopup){ //Define arbitrary function to run desired DHTML Window widget codes
inventorywin=dhtmlwindow.open("ajaxbox", "ajax", "http://thrilling-tales.webomator.com/projects/test/inventory/'+invpopup+'.html", " ", "width=720px,height=525px,center=1,resize=0,scrolling=0");
}

...with the idea the name of my html file will get passed as the variable "invpopup" and be placed into the file path. Now, I've found elsewhere in the project that I need to drop in the variable in different ways, like


'+eval(invpopup)+'

(which doesn't work either), and I've tried varying the syntax of the way I'm referring to the variable. This is because when it comes to Javascript I tend to bumble toward my solutions.

Anyway it seems unlikely that it can't be done, but I'm pretty much at a loss to figure out exactly how it can be done.

Help?

Bradley W. Schenck
08-04-2009, 03:57 PM
Okay, here's the answer. The function need to build a string with the entire line used to launch the popup, and then evaluate that string. Like this:


function open_inventory(invpopup){ //Define arbitrary function to run desired DHTML Window widget codes
var feedme='inventorywin=dhtmlwindow.open("ajaxbox", "ajax", "http://thrilling-tales.webomator.com/projects/test/inventory/'+invpopup+'.html", " ", "width=720px,height=525px,center=1,resize=0,scrolling=0")';
eval(feedme);
}