Jump to content

Color swatches


graficus

Recommended Posts

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

  • 3 weeks later...

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.