Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.