Jump to content

Simple image script


lamboman

Recommended Posts

I am looking for a very simple script. I need to have 4 images one one side of the screen, when either of them is clicked a single image on the other side of the screen will change according to what is clicked. All the images are different including the otherones on the side of the screen.

 

Any help is appriciated

Thanks in advance

Link to comment
Share on other sites

What I would do is add an onclick event to each of the 4 images. They can then call a function, passing in a different variable each. Then based on this variable, use a switch statement to decide what to change the other image to. For example, your 4 images would be something like

<img src="img1.jpg" onClick="changeImg('img1')"/>
<img src="img2.jpg" onClick="changeImg('img2')"/>
...
...

 

your changeImg function could look like

function changImg(which){
switch(which){
case "img1":
     //code to change it to whatever image 1 changes it into
     break;
case "img2":
     //code to change it to whatever image 2 changes it into
     break;
...
...
}
}//end function

 

Hope that helps

Link to comment
Share on other sites

Ok maybe this will be eisier. One side of the page has a couple buttons. Depending which button is pressed, an image will be displayed on the other side of the page. I know I am close with this script, but it still doesnt work.

 

(Here is my variables and function:)

 

<SCRIPT LANGUAGE="JavaScript">

function chosen(img_name,img_src) {

document[img_name].src=img_src;

}

 

<!--

if (document.images) {

  pic1 = new Image();

  pic1.src = "..pic1.gif";

  pic2 = new Image();

  pic2.src = "..pic2.gif";

}

 

//-->

</SCRIPT>

 

(Here is my buttons:)

 

<button type="button" chosen="pic1()">Show Image 1</button>

<button type="button" chosen="pic2()">Show Image 2</button>

 

(And here is where I want the image displayed acording to the button selected:)

 

<p id="chosen">

 

Hope that makes some sence.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.