Jump to content
MakeWebGames

Changing colors in a dropdown


Seker

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...