switch pic?

Discussion in 'Javascript' started by roN, May 20, 2006.

  1. roN

    roN Guest

    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>
    
    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'
    roN, May 20, 2006
    #1
    1. Advertising

  2. roN

    Randy Webb Guest

    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/
    Randy Webb, May 21, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dixon
    Replies:
    4
    Views:
    555
    Piotr Dobrowolski
    Jan 30, 2006
  2. Onur Bozkurt
    Replies:
    0
    Views:
    381
    Onur Bozkurt
    Jun 30, 2003
  3. Daniel
    Replies:
    1
    Views:
    305
    clintonG
    Jul 10, 2004
  4. Lasse Edsvik

    Text -> pic?

    Lasse Edsvik, Sep 28, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    626
    Scott Allen
    Sep 28, 2004
  5. Switch Within A Switch

    , Apr 22, 2006, in forum: Javascript
    Replies:
    7
    Views:
    95
    Lasse Reichstein Nielsen
    Apr 22, 2006
Loading...

Share This Page