Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-17-2012, 05:58 PM   PM User | #1
DrDOS
Senior Coder

 
Join Date: Sep 2010
Posts: 1,155
Thanks: 10
Thanked 148 Times in 148 Posts
DrDOS is infamous around these parts
Named colors select box php

When called the buildColors function will generate a drop down box with all the x-window named colors, 139 in all. All browsers recognize them by name. The value entry of the options can be set to the # value of the color, the name of the color, or the index of the array for that color. You can call it as many times as you need on a page. The selects are named such as to build an array named myinputs when posted.
PHP Code:
<?php
$colors 
= array();
$colors[] = array("AliceBlue","#F0F8FF");
$colors[] = array("AntiqueWhite","#FAEBD7");
$colors[] = array("Aqua","#00FFFF");
$colors[] = array("Aquamarine","#7FFFD4");
$colors[] = array("Azure","#F0FFFF");
$colors[] = array("Beige","#F5F5DC");
$colors[] = array("Bisque","#FFE4C4");
$colors[] = array("Black","#000000");
$colors[] = array("BlanchedAlmond","#FFEBCD");
$colors[] = array("Blue","#0000FF");
$colors[] = array("BlueViolet","#8A2BE2");
$colors[] = array("Brown","#A52A2A");
$colors[] = array("BurlyWood","#DEB887");
$colors[] = array("CadetBlue","#5F9EA0");
$colors[] = array("Chartreuse","#7FFF00");
$colors[] = array("Chocolate","#D2691E");
$colors[] = array("Coral","#FF7F50");
$colors[] = array("CornflowerBlue","#6495ED");
$colors[] = array("Cornsilk","#FFF8DC");
$colors[] = array("Crimson","#DC143C");
$colors[] = array("Cyan","#00FFFF");
$colors[] = array("DarkBlue","#00008B");
$colors[] = array("DarkCyan","#008B8B");
$colors[] = array("DarkGoldenRod","#B8860B");
$colors[] = array("DarkGray","#A9A9A9");
$colors[] = array("DarkGreen","#006400");
$colors[] = array("DarkKhaki","#BDB76B");
$colors[] = array("DarkMagenta","#8B008B");
$colors[] = array("DarkOliveGreen","#556B2F");
$colors[] = array("Darkorange","#FF8C00");
$colors[] = array("DarkOrchid","#9932CC");
$colors[] = array("DarkRed","#8B0000");
$colors[] = array("DarkSalmon","#E9967A");
$colors[] = array("DarkSeaGreen","#8FBC8F");
$colors[] = array("DarkSlateBlue","#483D8B");
$colors[] = array("DarkSlateGray","#2F4F4F");
$colors[] = array("DarkTurquoise","#00CED1");
$colors[] = array("DarkViolet","#9400D3");
$colors[] = array("DeepPink","#FF1493");
$colors[] = array("DeepSkyBlue","#00BFFF");
$colors[] = array("DimGray","#696969");
$colors[] = array("DodgerBlue","#1E90FF");
$colors[] = array("FireBrick","#B22222");
$colors[] = array("FloralWhite","#FFFAF0");
$colors[] = array("ForestGreen","#228B22");
$colors[] = array("Fuchsia","#FF00FF");
$colors[] = array("Gainsboro","#DCDCDC");
$colors[] = array("GhostWhite","#F8F8FF");
$colors[] = array("Gold","#FFD700");
$colors[] = array("GoldenRod","#DAA520");
$colors[] = array("Gray","#808080");
$colors[] = array("Green","#008000");
$colors[] = array("GreenYellow","#ADFF2F");
$colors[] = array("HoneyDew","#F0FFF0");
$colors[] = array("HotPink","#FF69B4");
$colors[] = array("IndianRed","#CD5C5C");
$colors[] = array("Indigo","#4B0082");
$colors[] = array("Ivory","#FFFFF0");
$colors[] = array("Khaki","#F0E68C");
$colors[] = array("Lavender","#E6E6FA");
$colors[] = array("LavenderBlush","#FFF0F5");
$colors[] = array("LawnGreen","#7CFC00");
$colors[] = array("LemonChiffon","#FFFACD");
$colors[] = array("LightBlue","#ADD8E6");
$colors[] = array("LightCoral","#F08080");
$colors[] = array("LightCyan","#E0FFFF");
$colors[] = array("LightGoldenRodYellow","#FAFAD2");
$colors[] = array("LightGrey","#D3D3D3");
$colors[] = array("LightGreen","#90EE90");
$colors[] = array("LightPink","#FFB6C1");
$colors[] = array("LightSalmon","#FFA07A");
$colors[] = array("LightSeaGreen","#20B2AA");
$colors[] = array("LightSkyBlue","#87CEFA");
$colors[] = array("LightSlateGray","#778899");
$colors[] = array("LightSteelBlue","#B0C4DE");
$colors[] = array("LightYellow","#FFFFE0");
$colors[] = array("Lime","#00FF00");
$colors[] = array("LimeGreen","#32CD32");
$colors[] = array("Linen","#FAF0E6");
$colors[] = array("Magenta","#FF00FF");
$colors[] = array("Maroon","#800000");
$colors[] = array("MediumAquaMarine","#66CDAA");
$colors[] = array("MediumBlue","#0000CD");
$colors[] = array("MediumOrchid","#BA55D3");
$colors[] = array("MediumPurple","#9370D8");
$colors[] = array("MediumSeaGreen","#3CB371");
$colors[] = array("MediumSlateBlue","#7B68EE");
$colors[] = array("MediumSpringGreen","#00FA9A");
$colors[] = array("MediumTurquoise","#48D1CC");
$colors[] = array("MediumVioletRed","#C71585");
$colors[] = array("MidnightBlue","#191970");
$colors[] = array("MintCream","#F5FFFA");
$colors[] = array("MistyRose","#FFE4E1");
$colors[] = array("Moccasin","#FFE4B5");
$colors[] = array("NavajoWhite","#FFDEAD");
$colors[] = array("Navy","#000080");
$colors[] = array("OldLace","#FDF5E6");
$colors[] = array("Olive","#808000");
$colors[] = array("OliveDrab","#6B8E23");
$colors[] = array("Orange","#FFA500");
$colors[] = array("OrangeRed","#FF4500");
$colors[] = array("Orchid","#DA70D6");
$colors[] = array("PaleGoldenRod","#EEE8AA");
$colors[] = array("PaleGreen","#98FB98");
$colors[] = array("PaleTurquoise","#AFEEEE");
$colors[] = array("PaleVioletRed","#D87093");
$colors[] = array("PapayaWhip","#FFEFD5");
$colors[] = array("PeachPuff","#FFDAB9");
$colors[] = array("Peru","#CD853F");
$colors[] = array("Pink","#FFC0CB");
$colors[] = array("Plum","#DDA0DD");
$colors[] = array("PowderBlue","#B0E0E6");
$colors[] = array("Purple","#800080");
$colors[] = array("Red","#FF0000");
$colors[] = array("RosyBrown","#BC8F8F");
$colors[] = array("RoyalBlue","#4169E1");
$colors[] = array("SaddleBrown","#8B4513");
$colors[] = array("Salmon","#FA8072");
$colors[] = array("SandyBrown","#F4A460");
$colors[] = array("SeaGreen","#2E8B57");
$colors[] = array("SeaShell","#FFF5EE");
$colors[] = array("Sienna","#A0522D");
$colors[] = array("Silver","#C0C0C0");
$colors[] = array("SkyBlue","#87CEEB");
$colors[] = array("SlateBlue","#6A5ACD");
$colors[] = array("SlateGray","#708090");
$colors[] = array("Snow","#FFFAFA");
$colors[] = array("SpringGreen","#00FF7F");
$colors[] = array("SteelBlue","#4682B4");
$colors[] = array("Tan","#D2B48C");
$colors[] = array("Teal","#008080");
$colors[] = array("Thistle","#D8BFD8");
$colors[] = array("Tomato","#FF6347");
$colors[] = array("Turquoise","#40E0D0");
$colors[] = array("Violet","#EE82EE");
$colors[] = array("Wheat","#F5DEB3");
$colors[] = array("White","#FFFFFF");
$colors[] = array("WhiteSmoke","#F5F5F5");
$colors[] = array("Yellow","#FFFF00");
$colors[] = array("YellowGreen","#9ACD32");

function 
buildColors($colors)
    {
    echo 
"<select name=\"myinputs[]\" class=\"myselects\">\n";
    for ( 
$count $count count($colors) ; $count++ ){
    echo 
"<option value=\"".$colors[$count][1]."\" >".$colors[$count][0]."</option>\n";} 
    echo 
"</select>\n\n";
    }
?>
DrDOS is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:23 AM.


Advertisement
Log in to turn off these ads.