...

View Full Version : Change Image with Drop Down?



Wynder
11-08-2005, 08:35 PM
Greetings, folks...

I am a near-absolute javascript noob, although I do have a pretty extensive background in programming. What I'm looking to do is the following...

I'd like a drop down box that lists, for instance, colors and, just to the right of that, have a JPG of that color. When the drop down box is changed, it'll automatically load the image of the color the person has selected.

I've searched the web over for example code to do this, but haven't found anything this specific. Anyone able to lend a hand here?

vwphillips
11-08-2005, 09:20 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
var Path='http://www.vicsjavascripts.org.uk/StdImages/';

function CngColor(obj){
index=obj.selectedIndex;
if (index<1){ return; }
document.getElementById('Img1').src=Path+obj.options[index].value;
}
//-->
</script></head>

<body>
<select onchange="CngColor(this);" >
<option >Select</option>
<option value="Zero.gif" >Zero</option>
<option value="One.gif" >1</option>
<option value="Two.gif" >2</option>
<option value="Three.gif" >3</option>
<option value="Four.gif" >4</option>
</select>
<img id="Img1" src="http://www.vicsjavascripts.org.uk/StdImages/Blank.gif" width=100 height=100 >
</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum