Click to See Complete Forum and Search --> : obj.someEvent = 'call myFunc with some param' how-to?


bon
12-16-2003, 06:03 AM
Hi,

I have created some images and would like to set their onClick event so that when an image is clicked a function is called with a parameter which depends on the exact image. I have:

var thumb_img = document.createElement("IMG");
thumb_img.src = "somepic.jpg"


I would like a click on thumb_img to result in a larger version of this picture being shown elsewhere on the page. I have a function setMainPic() that given a sourcepath sets the sourcepath of a large image on the page, so I tried something like

thumb_img.onClick = setMainPic(thumb_img.src);

Ofcourse this just assigns the result of the call setMainPic(thumb_img.src) to thumb_img.onClick, which is not what I wanted. I want the call setMainPic(thumb_img.src) to be executed as a result of an onClick event.
In short, what I need is a high-order function to return a specialized version of setMainPic.
How should I go about doing this?

- Bon

fredmv
12-16-2003, 01:48 PM
thumb_img.onclick = function() { setMainPic(thumb_img.src); }

bon
12-18-2003, 02:54 PM
Thanks