set background color doesn't work

For general web development questions that are not specifically related to CSS HTML Validator. This includes (but is not limited to) general HTML, CSS, Accessibility, JavaScript, and SEO questions.
Post Reply
maichel
Rank 0 - Newcomer
Posts: 6
Joined: Mon Oct 05, 2015 8:13 am

set background color doesn't work

Post by maichel »

Hello,

I have made code. The meaning is if you click on the color in the <option> then the background color change.
But this doesn't work.

Can someone help me?

thanks in advance.

Code: Select all

<?php

$red = "";
$yellow = "";
$blue = "";
$orange = "";
$purple = "";

if (isset($_POST['color'])) {$color = $_POST['color'];}
else {$color = '';}
?>

<html>
<head>
<title>color changer</title>
<style>
option.red { background-color: red; }
option.yellow { background-color: yellow; }
option.blue { background-color: blue; }
option.orange { background-color: #FF8040; }
option.purple { background-color: #800080; }


</style>
</head>
<body bgcolor="<?php echo color; ?>">

<form action="" method="POST">
<select name="background">
		<option style="display:none;" selected="selected">color</option>
		<option class="red" value="red" <?php echo $red; ?>>Red</option>
		<option class="yellow" value="yellow" <?php echo $yellow; ?>>Yellow</option>
		<option class="blue" value="blue" <?php echo $blue; ?>>Blue</option>
		<option class="orange" value="orange" <?php echo $orange; ?>>Orange</option>
		<option class="purple" value="purple" <?php echo $purple; ?>>Purple</option>
	</select>
<input type="submit" name="submit" value="change">
</form>

</body>
</html>
Post Reply