set background color doesn't work

Discussion about any web related scripting languages like JavaScript, ASP, and PHP.
Post Reply
maichel
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 6
Joined: Mon Oct 05, 2015 8:13 am

set background color doesn't work

Post by maichel » Wed Oct 14, 2015 8:34 am

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