lamboman Posted May 27, 2011 Share Posted May 27, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/237655-simple-image-script/ Share on other sites More sharing options...
mikesta707 Posted May 27, 2011 Share Posted May 27, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/237655-simple-image-script/#findComment-1221354 Share on other sites More sharing options...
lamboman Posted May 30, 2011 Author Share Posted May 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237655-simple-image-script/#findComment-1222559 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.