Jump to content

Variable and Textbox color?


BigDC

Recommended Posts

Hello,

I have a script that has an html page with a form on it. On this page is 3 different text boxes. I also have 3 variables named, $tbox1, $tbox2, and $tbox3. Each variable has a different hex color code stored in it that has been pulled from my database. My question, how can I use the hex codes stored in these variables to change the standard white color of all 3 text boxes (not the text color) to the three different hex colors stored in the variables?

 

$tbox2 = ....Hex color code from database is received;
$tbox2 = ....Hex color code from database is received;
$tbox2 = ....Hex color code from database is received;

echo'
<input type="text" ID="t1" name="tbox1" size="29" value=""><p>
<input type="text" ID="t2" name="tbox2" size="29" value=""><p>
<input type="text" ID="t3" name="tbox3" size="29" value=""><p>';

 

I need to know two different ways to do this, and they are:

1. When the page loads?

2. When a button is clicked?

 

Please help, as I am completely stumped?

 

-Thanks!

Link to comment
https://forums.phpfreaks.com/topic/177154-variable-and-textbox-color/
Share on other sites

you can't do when a button is clicked with pure PHP. you will need javascript. but for when the page loads you can do

 

echo'
<input type="text" ID="t1" style='background-Color:$tbox1' name="tbox1" size="29" value=""><p>
<input type="text" ID="t2" style='background-Color:$tbox2' name="tbox2" size="29" value=""><p>
<input type="text" ID="t3" style='background-Color:$tbox3' name="tbox3" size="29" value=""><p>';

 

this assumes the hex codes also include the pound(#) sign, IE look like #CCCCCC

you can't do when a button is clicked with pure PHP. you will need javascript. but for when the page loads you can do

 

echo'
<input type="text" ID="t1" style='background-Color:$tbox1' name="tbox1" size="29" value=""><p>
<input type="text" ID="t2" style='background-Color:$tbox2' name="tbox2" size="29" value=""><p>
<input type="text" ID="t3" style='background-Color:$tbox3' name="tbox3" size="29" value=""><p>';

 

this assumes the hex codes also include the pound(#) sign, IE look like #CCCCCC

 

Oh ok. So how would I do it with javascript using a button?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.