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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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