Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: CGI Colour Palette (Javascript Solution)

by BigLug (Chaplain)
on Aug 09, 2002 at 01:42 UTC ( #188801=note: print w/replies, xml ) Need Help??


in reply to CGI Colour Palette

Although this is a JS solution, it could be modified to perl. The reason its in JS is that by sending the full table out (as you'd do with a perl solution), you're outputting a lot more data than is needed.

I use the following javascript to let people select a color in a form text field. The text field lets them type a color if they know it, or they click a button to choose one:

function choosecolor(form, name, title) { colorWindow=window.open("about:blank","colorWindow","width=400 +,height=120,resizable=yes") colorlist = new Array('00','33','66','99','CC','FF'); colorWindow.document.write("<table border=0 cellpadding=0 cell +spacing=0>"); colorWindow.document.write("<tr><td colspan=3 align=center><fo +nt face='arial,helvetica,sans' size=3><b>" + title + "</b></td></tr>" +); colorWindow.document.write(" <tr>"); for (var rcolor in colorlist) { colorWindow.document.write(" <td>"); colorWindow.document.write(" <table border=0 ce +llpadding=0 cellspacing=2>"); for (var gcolor in colorlist) { colorWindow.document.write(" <tr>"); for (var bcolor in colorlist) { colorWindow.document.write(" <t +d bgcolor='#" + colorlist[rcolor] + colorlist[bcolor] + colorlist[gco +lor] + "'><a href=\"javascript:window.opener.document." + form + "." ++ name + ".value='#" + colorlist[rcolor] + colorlist[bcolor] + colorl +ist[gcolor] + "'; self.close()\"><img src="./images/clearpixel.gif' w +idth=8 height=8 border=0></a></td>"); } colorWindow.document.write(" </tr>"); } colorWindow.document.write(" </table>"); colorWindow.document.write(" </td>"); } colorWindow.document.write(" </tr>"); colorWindow.document.write("</table></font><form><input type=b +utton value=' Cancel ' onclick='self.close()'></form></center>");
Which works from a form like this:
<form name=colorpicker> Enter a color:<input name=color type=text><input type=button value="Pi +ck" onclick="choosecolor('colorpicker', 'color', 'Pick a color for no + reason at all')"> </form>
Hope this helps ... please forgive the lack of a perl solution, but note the above reasoning for it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://188801]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2019-06-17 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (80 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!