Apr
19

What about a color picker for a cfform?

6 comments Posted by: Nahuel

Following my previous post about the slider, in this example I created a color picker with three sliders, red, green and blue. On the onChange event of these sliders, I'm updating the color of the rectangle to reflect the changes.

This is the code:

<cfsavecontent variable="onValueChange">
   
   function comp2Hex(val)
   {
       return (val<16) ? "0" + val.toString(16) : val.toString(16);
   }
   var red = Number(slideRed.text);
   var green = Number(slideGreen.text);
   var blue = Number(slideBlue.text);
   var rgb = red << 16 | green << 8 | blue;
   var c = Number("0x"+comp2Hex(rgb));
   colorDisplay.setStyle("backgroundColor", c);
</cfsavecontent>

<cfform name="myform" height="200" width="300" format="Flash" timeout="1000">
   <cfformgroup type="horizontal">
      <cf_slider name="slideRed" minValue="0" maxValue="255" onChange="#onValueChange#"
             showValues="false" thumStyle="cornerRadius:4; borderThickness:1;">

      <cfinput name="trace" type="text" width="40" bind="{slideRed.text}"/>
   </cfformgroup>
   <cfformgroup type="horizontal">
      <cf_slider name="slideGreen" minValue="0" maxValue="255" onChange="#onValueChange#"
             showValues="false" thumStyle="cornerRadius:4; borderThickness:1;">

      <cfinput name="trace1" type="text" width="40" bind="{slideGreen.text}"/>
   </cfformgroup>
   <cfformgroup type="horizontal">
      <cf_slider name="slideBlue" minValue="0" maxValue="255" onChange="#onValueChange#"
             showValues="false" thumStyle="cornerRadius:4; borderThickness:1;">

      <cfinput name="trace2" type="text" width="40" bind="{slideBlue.text}"/>
   </cfformgroup>
   <cfinput type="text" name="colorDisplay" disabled="true"
          style="borderStyle:none; backgroundColor:##ffffff">

</cfform>

You can view a live example
Download the source.

Category: CFForm | ColdFusion |

6 Comments so far

Write yours
Doug Hughes
You guys never cease to amaze me!
phill.nacelli
2. phill.nacelli wrote on April 19, 2005 at 2:32 PM
DITTO.... DITTO... You guys absolutely rock!!! Thank You! Thank You! Thank You!...
Mathij
3. Mathij wrote on April 20, 2005 at 1:12 AM
wow this rocks! what i'm also looking for is a color picker from predefined Hex colors. I that also possible with flash and cfform?
Steven Ross
when i browse this it loads the thumbnails then they dissapear... I am about to start using this code and just wondered if anyone else is seeing this.
Michael White
only one thing more would make it perfect. If you had a second box with the HEX values next to the first box that that was bound to the first and calculated on the fly. Can you have a calculated control bound to a control that is itself bound to a third control (slider in this case)?
Michael White
I see why you didn't include that function... I am surprised how hard it is to find the formula to convert from decimal to hex and coldfusion doesn't seem to have a built in function exposed.

Leave your comment

Comment etiquette: As a gesture to those subscribed to this post, please keep your comments relevant to the post.

Your email address will never be displayed.
Email is gravatar enabled.Gravatar are the pictures you see next to the comments. If you like to have one, visit gravatar



Allowed tags:

<code>
All other tags will be shown as such, when in doubt, use the preview.




Preview:

Refresh Preview
1. You wrote on