graficus Posted February 19, 2007 Share Posted February 19, 2007 Could you help me with this: I have a dynamic dropdown, and need to display a color swatch (jpg) next to it when a value gets selected. Paths to swatches cannot be stored in DB, so if possible, they need to be simply connected with value in the dropdown (value1=value1.jpg) Is this do-able? PS: here is an example of color selection I need Thank you Link to comment https://forums.phpfreaks.com/topic/39107-color-swatches/ Share on other sites More sharing options...
mainewoods Posted March 8, 2007 Share Posted March 8, 2007 give your swatch image an id: <img id="swatchimage" src="*****"> you can change the src attribute of the image on the fly using javascript: document.getElementById("swatchimage").src = "new image filename"; http://www.w3schools.com/htmldom/prop_img_src.asp Get the value of the select box: http://www.w3schools.com/htmldom/dom_obj_select.asp Add an onchange event to your select box: <select name="yourname" onchange="changeswatch();"> changeswatch() will contain code for retrieving the current value of the select box and creating a filename out of that and then using the javascript statement above to change the src of your swatch image to it. Link to comment https://forums.phpfreaks.com/topic/39107-color-swatches/#findComment-202224 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.