468,136 Members | 1,451 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,136 developers. It's quick & easy.

switch pic?

roN
Hi,

I have 3 small images and 3 big images, i would like to display the big one,
when the small one is clicked, I tried:
[js]
IA1 = new Image();
IA1.src = "./images/IA-demo-big_1.jpg"; /* first big IA image */
IA2 = new Image();
IA2.src = "./images/IA-demo-big_2.jpg"; /* second big IA image */
IA3 = new Image();
IA3.src = "./images/IA-demo-big_3.jpg"; /* third big IA image */
function switchpic(pic)
{
window.document.images['big'].src = IA[pic].src;
}
[/js]
[html]
<td width="23%"><a href="#"
OnClick="switchpic(1)"><img src="images/IA-demo-small_1.jpg" width="63"
height="95" border="0"></a></td>
<td colspan="3" rowspan="3"><img
src="images/IA-demo-big_3.jpg" name="big" width="193" height="290"></td>
</tr>
<tr>
<td><a href="#" OnClick="switchpic(2)"><img
src="images/IA-demo-small_2.jpg" width="63" height="95"
border="0"></a></td>
</tr>
<tr>
<td><a href="#" OnClick="switchpic(3)"><img
src="images/IA-demo-small_3.jpg" width="63" height="95"
border="0"></a></td>
</tr>
[/html]

but it wouldn't work, why not?
I'd appreciate your help!
Thank you!
--
chEErs roN

I'm root, I'm allowed to do this! ;)
keep on rockin'
May 21 '06 #1
1 1141
roN said the following on 5/20/2006 5:08 PM:
Hi,

I have 3 small images and 3 big images, i would like to display the big one,
when the small one is clicked, I tried:
[js]
IA1 = new Image();
IA1.src = "./images/IA-demo-big_1.jpg"; /* first big IA image */
IA2 = new Image();
IA2.src = "./images/IA-demo-big_2.jpg"; /* second big IA image */
IA3 = new Image();
IA3.src = "./images/IA-demo-big_3.jpg"; /* third big IA image */
function switchpic(pic)
{
window.document.images['big'].src = IA[pic].src;
}


IA is not an array so you can't access it like that. Either make IA an
array or use window['IA' + pic].src;

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Rudi Hansen | last post: by
10 posts views Thread by Myster Ious | last post: by
5 posts views Thread by Bryan Parkoff | last post: by
10 posts views Thread by clueless_google | last post: by
65 posts views Thread by He Shiming | last post: by
3 posts views Thread by pgraeve | last post: by
11 posts views Thread by ME | last post: by
12 posts views Thread by | last post: by
11 posts views Thread by =?Utf-8?B?anAybXNmdA==?= | last post: by
27 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.