Seker Posted August 30, 2012 Share Posted August 30, 2012 So, I'm trying to set it up so players can choose their own font color for my game's chat. The color codes are to be put into an array, and I want the choices to show up as the color the player is selecting. I just cannot get it to work. To better understand it, here's an example I tried: $coloroptions = array(1 => '#00FFFF'); echo " <form action='preferences.php?action=chatcolor' method='post' /> <select name='color'>"; foreach($coloroptions as $colorcode => $colorname) { echo " <option value='", $colorcode ,"'><font style='color:", $colorname, ";'>", $colorname ,"</font></option>"; } echo " </select> <input type='submit' value='Select Color' /></form>"; Now, in the dropdown, the code #00FFFF should show up as an aqua color. But it's still just black text on a white background. Any ideas? Quote Link to comment Share on other sites More sharing options...
Octarine Posted August 30, 2012 Share Posted August 30, 2012 css styles Quote Link to comment Share on other sites More sharing options...
Seker Posted August 30, 2012 Author Share Posted August 30, 2012 css styles So, what are you trying to tell me here? I need to use the color name and not the code? I need to select the color inside the option? Tried that. Instead of using an array, I need to type out every single option? Edit: Not trying to be rude if that's how I've come off. This has just been giving me some trouble for the past half hour or so. :P Quote Link to comment Share on other sites More sharing options...
Octarine Posted August 30, 2012 Share Posted August 30, 2012 Maybe this is clearer. I'm sure you can figure out how to do this from PHP. What is different between this and your code? What makes this work and your code ... not work? Quote Link to comment Share on other sites More sharing options...
Spudinski Posted August 30, 2012 Share Posted August 30, 2012 I'd suggest: http://www.jankoatwarpspeed.com/post/2009/07/28/reinventing-drop-down-with-css-jquery.aspx Quote Link to comment Share on other sites More sharing options...
sniko Posted August 30, 2012 Share Posted August 30, 2012 <?php /* "color" -> hex value of the colour, including hash # "style" -> background colour of the option && text colour of the option "tag" -> what it will display in the option */ $colours = array( '#FFFFFF' => array('style' => 'background:#CCCCCC;color:#000000', 'tag' => 'White'), '#000000' => array('style' => 'background:#3C3C3C;color:#FFFFFF', 'tag' => 'Black'), ); if( isset($_POST['submit']) ) { if( array_key_exists($_POST['colour'], $colours) == FALSE ) { /* Not a colour in the array */ echo 'Choose again'; } else { /* Everything OK */ echo 'Colour changed!'; // mysql_query("UPDATE `users` SET `chat_colour`='{$_POST['colour']}' WHERE `userid`={$userid}"); } } echo '<form action="" method="post">'; echo '<select name="colour">'; echo '<option value="">--- Choose One ---</option>'; foreach( $colours as $colour => $additional) { echo '<option value="'. $colour .'" style="'. $additional['style'] .'">'. $additional['tag'] .'</option>'; } echo '</select>'; echo '<input type="submit" value="Do" name="submit" /> </form>'; ?> http://pastebin.com/T6DcPNi5 Quote Link to comment Share on other sites More sharing options...
Seker Posted August 30, 2012 Author Share Posted August 30, 2012 Got this all worked out, but thanks for the help. :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.