set background color doesn't work

Discussion about any web related scripting languages like JavaScript, ASP, and PHP.
Post Reply
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 »


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


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

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

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

<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>
<input type="submit" name="submit" value="change">

Post Reply