"RobG" <rg***@iinet.net.auwrote in news:1164335309.561811.82520@
45g2000cws.googlegroups.com:
>hehe, the whole problem is making this work in IE. IE requires me to
assign onclick events via functions
How?
Well, though it may be improper, javascript as follows...
getElementById('myButton').onclick = "alert('hey now!');";
.... will give the element myButton an onclick event that gives you a
prompt saying 'hey now' in Firefox... but in IE, it does not, clicking
myButton won't do a thing. hence assigning it via a function
>thanks for your help, i solved it...
Badly.
woohoo! im a sucker for criticism.
>can just be rewritten as:
detachImage = getElementById('detach'+fileKey);
detachImage.onclick = function() { detachFile(detachImage) }
Which creates a closure back to the detachImage variable. If you use
this in a loop to put onclick events on two or more elements, then all
of your onclick handlers will reference the last element associated
with detachImage.
thanks, now I understand
Do it like this:
detachImage.onclick = function() { detachFile(this) }
And in detachFile:
function detachFile( refToElement) { ... }
refToElement will be set to a reference to the element that triggered
the event.
excellent, i will try that tomorrow when i have the code back in front
of me. sure enough, all the "detachImage"s that exist in the document
when loaded (ie: ones NOT created on the fly) have: onclick="detachFile
(this);" , so my detachFile function looks like yours already. so that
makes good sense.
Thanks.