Page 1 of 1
How do I make a select box, to change webpage colors?
Posted: Fri Sep 22, 2006 7:53 pm
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..
Posted: Fri Sep 22, 2006 7:59 pm
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; ?>">
Posted: Fri Sep 22, 2006 8:23 pm
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..
Posted: Fri Sep 22, 2006 8:47 pm
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>
Posted: Sat Sep 23, 2006 12:50 am
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
Posted: Sat Sep 23, 2006 1:40 am
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.'">';
Posted: Sat Sep 23, 2006 8:11 pm
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!