How do I make a select box, to change webpage colors?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Abomination
Forum Newbie
Posts: 7
Joined: Tue Sep 05, 2006 8:26 pm

How do I make a select box, to change webpage colors?

Post by Abomination »

How do I make a select box, like say

Theres a box that says white or black w/e you want, you click what you want then hit submit, it changes the whole webpage background to black or white w/e is in teh box...

Code: Select all

<html>
<head>
<title>
</title>
</head>

<body>

<form method='post' action='change.php'>
<select name='tname'><option selected value='White'><option value='white'>White</option><option value='black'>Black</option></select>
<input type='submit'>
</form>
</body>
</html>
So please feedback..
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Hmm.

Suppose it could be done in javascript.

<select onchange="document.style.backgroundColor=(this.value);">

ORRRRRR

If you're looking for like skins or something? Store the users choice in a db or cookie or session or storage method of choice. Then on your pages:

Code: Select all

<body bgcolor="<?php echo $users_bg_color_choice; ?>">
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Abomination
Forum Newbie
Posts: 7
Joined: Tue Sep 05, 2006 8:26 pm

Post by Abomination »

Code: Select all

<html>
<head>
<title>
</title>
</head>

<body bgcolor=<?php get=$bgcol?> >

<form method='post' action='change.php'>
<select name='tname'><option selected value='black'><option value='white'>White</option><option value='black'>Black</option></select>
<input type='submit'>
</form>
</body>
</html>

<?php

$black=$_POST['black'];
$white=$_POST['white'];
$bgcol=$_POST['null'];

if($black=='true') {

$bgcol='white'
}

if($white=='true') {

$bgcol='black'
}
?>
I just can't do something along those lines? I dunno the propper code, maybe you could say..
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

Code: Select all

<html>
<head>
<title>
</title>
</head>
<?php
If ($_GET['bgcolor']==null)
{
$bgcolor="white"; //Replace in the quotes with the default color you want
}
elseif ($_GET['bgcolor']=="white")
{
$bgcolor = "white";
}
elseif ($_GET['bgcolor']=="black")
{
$bgcolor = "black";
} ?>
<body bgcolor="<?php echo $bgcolor; ?>">

<form method='post' action='change.php'>
<select name='bgcolor'><option selected value='White'><option value='white'>White</option><option value='black'>Black</option></select>
<input type='submit'>
</form>
</body>
</html>
Maybe that? You might also want to add to it so that when $bgcolor is black, the text will be white.

An even simpler way to do this would be:

Code: Select all

<html>
<head>
<title>
</title>
</head>
<?php
If ($_GET['bgcolor']==null)
{
$bgcolor="white"; //Replace in the quotes with the default color you want
}
else
{
$bgcolor = $_GET['bgcolor'];
}
?>
<body bgcolor="<?php echo $bgcolor; ?>">

<form method='post' action='change.php'>
<select name='bgcolor'><option selected value='White'><option value='white'>White</option><option value='black'>Black</option></select>
<input type='submit'>
</form>
</body>
</html>
Abomination
Forum Newbie
Posts: 7
Joined: Tue Sep 05, 2006 8:26 pm

Post by Abomination »

GWsux wrote:

Code: Select all

<html>
<head>
<title>
</title>
</head>
<?php
If ($_GET['bgcolor']==null)
{
$bgcolor="white"; //Replace in the quotes with the default color you want
}
elseif ($_GET['bgcolor']=="white")
{
$bgcolor = "white";
}
elseif ($_GET['bgcolor']=="black")
{
$bgcolor = "black";
} ?>
<body bgcolor="<?php echo $bgcolor; ?>">

<form method='post' action='change.php'>
<select name='bgcolor'><option selected value='White'><option value='white'>White</option><option value='black'>Black</option></select>
<input type='submit'>
</form>
</body>
</html>
Maybe that? You might also want to add to it so that when $bgcolor is black, the text will be white.

An even simpler way to do this would be:

Code: Select all

<html>
<head>
<title>
</title>
</head>
<?php
If ($_GET['bgcolor']==null)
{
$bgcolor="white"; //Replace in the quotes with the default color you want
}
else
{
$bgcolor = $_GET['bgcolor'];
}
?>
<body bgcolor="<?php echo $bgcolor; ?>">

<form method='post' action='change.php'>
<select name='bgcolor'><option selected value='White'><option value='white'>White</option><option value='black'>Black</option></select>
<input type='submit'>
</form>
</body>
</html>

Tried both..

Non work.. This is what I get =

http://changelayouttest.awardspace.com
lecram
Forum Newbie
Posts: 20
Joined: Wed Sep 06, 2006 10:12 am

Post by lecram »

Code: Select all

<form method='post' action='change.php'>
<select name='tname'><option selected value='White'><option value='white'>White</option><option value='black'>Black</option></select>
<input type='submit'>
first examine that bit of code. for starters, your form action is "change.php." you should be using $_SERVER['PHP_SELF']

you need to define the name of your select field, not the option fields.

for instance,

$bgcolor = $_POST['bgcolor'];

then use an if statement to perform an action based on the element selected.

for instance,

Code: Select all

if($bgcolor == "Black"){
$background = "#000000";
} elseif($bgcolor == "White") {
$background = "#FFFFFF";
}

echo '<body bgcolor="'.$background.'">';
Abomination
Forum Newbie
Posts: 7
Joined: Tue Sep 05, 2006 8:26 pm

Post by Abomination »

Now can you right that so I can understand it?

Where do I put $_SERVER['PHP_SELF']

Where do I put the if statements, What what what!
Post Reply