troubleshooting Question

image change using a select box

Avatar of niceoneishere
niceoneishere asked on
JavaScriptWeb DevelopmentHTML
15 Comments1 Solution342 ViewsLast Modified:
Hi Experts,
I am using a javascript function to change images upon selecting an option from a select box. here is my write up.

<script type="text/javascript" language="javascript">

function color_select(ID){
var colorElem = document.getElementById('color');
var color_dir = 'graphics/';
colorElem.src = color_dir + ID + '.jpg';

i have declared my img tag like this
<img id="color" src="graphics/image1.jpg" >

and my select box is like below
<select name="part_color"  onChange="color_select(this.value);">
<option value="100">Red</option>
<option value="101">Green</option>
<option value="102">Blue</option>

NOW THIS WORKS fine but there are some case where i wont have image to display for example BLUE color, so when i am selecting blue color i get a big "X" showing that there is no image

How can i change my code in such way when an option has no image and if i select it just displays no image or should say no preview available

Thanks everyone
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 15 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros