Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

seeking a color selector

Status
Not open for further replies.

longmatch

Programmer
Nov 1, 2001
406
I want to allow users to select colors for their report. I would like to have the color selector put on my form, when user select one, the color code will be saved into the database for further display for given field. Does anybody know whether there is any good 'color selector' easy to use?

Thanks

Longmatch
 
I found a few doing a google search. The basic idea, if you're ineterested in building one yourself, is to either create a tabvle with a lot of cells, each one with a differant color or to use an imagemap on top of a nice color selector image. You then use the onClick to set value of the color to an input or something similar.
Beware large color selectors, they load very slowly. I have an ASP class that I wrote which generates a HSB color selection table on the fly with a few million colors, it makes my server hurt every time I load it because each on of those colors is a cell in a table and no browser likes randering a table with a few million cells, or even a few million anything elses for that mater.

You would probably be able to get the best resolution by using either an ActiveX object, java applet, or Flash color chooser and then passing the value back to your page from inside that. I have a friend who built a very nice colorchooser in Flash at one point, I wouldn't be surprised if you could find one of those that would meet your needs.

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Do you know how hot your computer is running at home? I do
 
I have started to build one by myself. The map is built using map elements, total 18x12 colors. I would like to pop up one window when a 'select color' button is clicked. When a special color is chosen, the color code should be saved in a text box. Could you show me what is the logic behind if I want to do this way.


Thanks a million.

Longmatch
 
If you want to save it in a text ox on the original page, you could build a js function in the original page to accept two arguments and assign the value of the first argument to the value of the second argument, like so:
Code:
function setColor(elemId, colorStr){
   document.getElementById(elemId).value = colorStr;
}

Now what you would do is when you open your new window, provide it with a querystring argument to pass along the id of an input box that your going to want the color returned to. These Id's need to be unique.

When they click a color in the new window, have it call the parent windows function with the passed id string and the chosen color. You can pass the color to a js function in your colorchooser window to do this for you:
Code:
function passColor(colorStr){
   parent.setColor(&quot;<%=Request.QueryString(&quot;InputId&quot;)%>&quot;,colorStr);
}

You notice I just put the InputId in straight from the querystring, in your case it may be called something differant, basically it's just the querystring variable I suggested adding up above in the window open address.

If you already have the color map taken care of, than I think you should have the basis iof everything else from what I posted above, if I overlooked anything, please post back so one of us can fill in any blanks I left.

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Do you know how hot your computer is running at home? I do
 
Do you think to use SHOW/HIDDEN layer instead of new window will make this easier?

Longmatch


 
Possibly, except for then you will need to have some sort of javascript variable to hold on to the name of the input box your filling and you will need to be a little more careful about your show/hide routine because someone has the possibility of clicking another button while the color chooser is already shown. Other than that I don't see any real advantage or disadvantage to using a hidden div/layer except that you won't have a popup window, which might be an issue if you have a lot of people (increasing the chance that someone accesses your page and has a popup blocker).

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Do you know how hot your computer is running at home? I do
 
perhaps just use a hexidecimal function to generate an HTML page with <td bgcolor=&quot;<%=HexValue%>&quot; onclick=&quot;determinecolor(this);&quot;> ??

avoiding images and speeding up the page? cause the imagemap layout would be horrendous text in the html

just thoughts to help is all
 
Drexor: Like I mentioned, the efficiency depends on how you do it and whether you hard cod it or not (as well as the number of colors involved). I have an OC'd 1.6a P4 and a Gb of RAM, my machine won't even let me type for about 5 seconds when it is generating a color table. The again mine is not static, it's 100% dynamic looping through the entire HSB color scheme. This link will land you the source for a color chooser with only 2048 colors, Hue and Brightness combinations only, saturation not included.
I double checked and it appears I never took the Hue vs Brightness higher than 65536 colors. You'll notice that even static with only 2048 colors this document takes a while to load, even when being accessed locally.

One way to simplify this process would be to simply give the user a small viewing area and three bars, to control red, blue, green. Then you could change the background color values in your mini-color chooser based on the values in the sliders. This would allow you to have a much smaller table, but a much wider available spectrum.

This actually sounds like it would be neat to make, if I get any time and remember perhaps I'll do this like the digital clock and other wierd projects that have come down the road.

cheap clock plug:
-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Do you know how hot your computer is running at home? I do
 
here's a page and source for something like i was talking about .. threw it together quick WITH output of source code in page .. perhaps it'll help and as for the java part of it .. just adjust the background color modifyer to do whatever you want.


 
Tarwn
I was waiting for you to show that selector up! [wink]
i was about to mention showing it if you didn't

____________________________________________________
The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-2924

onpnt2.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top