Connecting Tech Pros Worldwide Help | Site Map

Changings the onClick of a image.

Ben
Guest
 
Posts: n/a
#1: Jul 23 '05
Hi,

I have a number of images whose src's are changed when a button is
pressed. At the moment the href is also changed and the images are
opened. However I have a function which opens the images in their own
windows. I want to run this for each image using the onClick event of
the image. I have all the images and links stored in there own
array's. I would like to do the same for the onClick events. I have
tried creating an array an storing the onClick events in it.
i.e. images_onClicks[2] =
"image_popup('image.jpg',100,100,100,100)";
and then changing the onclick event for the image.
i.e. document.getElementsByName("image1")[0].onclick =
images_onClicks[0];

However I just can't get it to work. Could anyone please tell me if
there is something that I am missing.

Thanks for your time.

Ben.
Lee
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Changings the onClick of a image.


Ben said:[color=blue]
>
>Hi,
>
>I have a number of images whose src's are changed when a button is
>pressed. At the moment the href is also changed and the images are
>opened. However I have a function which opens the images in their own
>windows. I want to run this for each image using the onClick event of
>the image. I have all the images and links stored in there own
>array's. I would like to do the same for the onClick events. I have
>tried creating an array an storing the onClick events in it.
> i.e. images_onClicks[2] =
>"image_popup('image.jpg',100,100,100,100)";
>and then changing the onclick event for the image.
> i.e. document.getElementsByName("image1")[0].onclick =
>images_onClicks[0];
>
>However I just can't get it to work. Could anyone please tell me if
>there is something that I am missing.[/color]

Three things:

1. The onclick attribute of an image must be a function.
You're trying to assign string values, not functions.

2. That's a very bad approach to the problem. You shouldn't
be changing the entire functions just to change the arguments
to your image_popup() function.

3. At least two people responded when you asked the same question
at least twice before. If you're not happy with those answers,
respond to them explaining why.

Closed Thread