[Javascript] Doubly-indirected function declaration
David Lovering
dlovering at gazos.com
Wed Aug 6 18:46:44 CDT 2003
I've got something of a teaser -- I'm building a hot-link list which
connects to a single function with parameters which are determined at
build-time (and will vary wildly from job-to-job, day-to-day, etc.). To
visually organize these babies I'm inserting the hotlinks inside a table.
Rather than try to use static HTML to "guess" magically what values should
be shipped to each function invocation cited by the hotlink, I'm
attempting instead to use the createElement process to insert a reference to
an on-click handler at each point, for example
for (var i=0; i<maxVal; i++) {
blah-blah-blah
var paramlist = "query_parent.php?name=" + formName + ..... +
"&type=table";
blah-blah-blah
function launchquery(paramlist) {
var win =
window.open(paramlist,"","titlebar=no,menubar=yes,location=no,status=no,link
s=no");
}
blah-blah-blah
newRow = myDoc.createElement("TR");
newRow.style.cursor = "hand";
myTd = myDoc.createElement("TD");
myTd.innerHTML = "yada-yada";
myTd.onclick = function anonymous(){launchquery(paramlist)}
newRow.appendChild(myTd);
topRow.appendChild(newRow);
}
I don't need to go into the details of how topRow is defined -- suffice to
say, it is the row below which the insertion is to take place.
The PROBLEM (!!!) is that the interior of the call-handler isn't defined
until the event which invokes it, by which time the loop has run its course
and the value(s) which get handled by launchquery are the last one(s)
defined -- NOT the ones which are defined at build time. This sucks.
I need a comparable method which will take the values defined at load-time,
and stuff them into the invocation, and then leave them unaltered.
Any ideas? I've tried all sorts of variations on eval, exec, etc., and so
far there is no joy in Mudville.
-- Dave Lovering
More information about the Javascript
mailing list