http://www.perlmonks.org?node_id=188801


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.