Forum Moderators: coopster

Message Too Old, No Replies

changing div bgcolor in php. how?

         

adfa

2:36 pm on Dec 16, 2007 (gmt 0)

10+ Year Member



i have this code:
<code>

<div id="WT_BG">
<div id="#trunks_form_container">
<div id="page_headings"><img src="images/page_headings/personalise.png" alt="design your own trunks" /></div>
<div id="personalise_LH_text"></div>
<div id="trunks_front">



<div id="trunks_container"><img name="trunks" src="images/plain-trunks-front_2nd.png" width="425" height="255" alt="" />


<div id="text_return_container">
<?php
$text_size = $_POST['size'];
$font = $_POST['font'];
$colour = $_POST['colour'];
$bg = $_POST['bg'];
$text = $_POST['personalise'];
echo "<span style=\" font-family:$font; color:$colour; font-size:$text_size; \">
$text
</span>\n";
?>
</div><!--end text return container-->
</div><!--end trunks container-->
<?php
"<span style=\" bgcolor:$bg\"></span>\n";
echo "$bg";
?>
</div><!--end trunks front-->
</div>
<!--end trunks form container-->
<div id="personalise_form">
<form method="POST" action="<?php echo $PHP_SELF;?>">
<p> <input type="text" name="personalise" value="Enter your text here" onfocus="if(this.value == 'Enter your text here') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Enter your text here';}"/></p>

<?php
// you need the values of your combobox in an array
$colourvalues = array('black','white','red','green','blue','orange','purple','cyan','pink');
$fontvalues = array('arial','helvetica','trebuchet MS','arial black','lucida console','verdana','comic sans MS','courier new','impact','century gothic','bookman old style','Microsoft Sans Serif');
$sizevalues = array('20px','30px','40px','50px','60px');
$trunkvalues = array('#000000','white','red','green','blue','orange','purple','cyan','pink');


echo '<select name="colour">';

for($x = 0; $x < count($colourvalues); $x++)
{
// write "selected" if the value matches the one posted
if($colourvalues[$x] == $_POST['colour'])
{
$colourselected = ' selected';
}else{
$colourselected = '';
}
// print the option
echo '<option value="'.$colourvalues[$x].'"'.$colourselected.'>'.$colourvalues[$x].'</option>';
}
echo '</select>';

echo '<select name="font">';

for($y = 0; $y < count($fontvalues); $y++)
{
// write "selected" if the value matches the one posted
if($fontvalues[$y] == $_POST['font'])
{
$fontselected = ' selected';
}else{
$fontselected = '';
}
// print the option
echo '<option value="'.$fontvalues[$y].'"'.$fontselected.'>'.$fontvalues[$y].'</option>';
}
echo '</select>';



echo '<select name="size">';

for($w = 0; $w < count($sizevalues); $w++)
{
// write "selected" if the value matches the one posted
if($sizevalues[$w] == $_POST['size'])
{
$sizeselected = ' selected';
}else{
$sizeselected = '';
}
// print the option
echo '<option value="'.$sizevalues[$w].'"'.$sizeselected.'>'.$sizevalues[$w].'</option>';
}
echo '</select>';


echo '<select name="bg">';

for($z = 0; $z < count($trunkvalues); $z++)
{
// write "selected" if the value matches the one posted
if($trunkvalues[$z] == $_POST['bg'])
{
$trunkselected = ' selected';
}else{
$trunkselected = '';
}
// print the option
echo '<option value="'.$trunkvalues[$z].'"'.$trunkselected.'>'.$trunkvalues[$z].'</option>';
}
echo '</select>';

?>

<p><input type="submit" name="submit" value="Show me this text on my briefs"/></p>
</form>
</div>
</div>

</code>

it doesn't matter what i try, i cannot get the background colour of 'trunks_front' div to change dynamically.
can anyone suggest what i am doing wrong here?

henry0

2:54 pm on Dec 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where do you call for "trunks_front" as a var, an if, a for or whatever in your script?

Please, explain how you expect that value to change and change upon what?

adfa

9:21 pm on Dec 16, 2007 (gmt 0)

10+ Year Member



hi.
thanks for the reply.
trunks_front is just the div. it isn't a variable.
<code>
<div id="trunks_front">



<div id="trunks_container"><img name="trunks" src="images/plain-trunks-front_2nd.png" width="425" height="255" alt="" />


<div id="text_return_container">
<?php
$text_size = $_POST['size'];
$font = $_POST['font'];
$colour = $_POST['colour'];
$bg = $_POST['bg'];
$text = $_POST['personalise'];
echo "<span style=\" font-family:$font; color:$colour; font-size:$text_size; \">
$text
</span>\n";
?>
</div><!--end text return container-->
</div><!--end trunks container-->
<?php
"<span style=\" bgcolor:$bg\"></span>\n";
echo "$bg";
?>
</div><!--end trunks front-->
</code>

it's the background colour of trunks_front that i want to change. the variable is $bg for this. the string is assigned via a form in which you can select the various colours.

adfa

9:22 pm on Dec 16, 2007 (gmt 0)

10+ Year Member



$bg is called towards the bottom of the code.
the echo $bg is just there as a temporary check.

dreamcatcher

11:15 am on Dec 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



bgcolor isn`t a style attribute. Should be 'background' or 'background-color'.

dc

adfa

2:50 pm on Dec 17, 2007 (gmt 0)

10+ Year Member



hi.
thanks for the reply. i have tried both of those but it doesn't seem to work. i don't know what i am doing wrong. it all looks ok but the background doesn't change.
any ideas?
thanks