BigDC Posted October 10, 2009 Share Posted October 10, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/177154-variable-and-textbox-color/ Share on other sites More sharing options...
mikesta707 Posted October 10, 2009 Share Posted October 10, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/177154-variable-and-textbox-color/#findComment-934098 Share on other sites More sharing options...
BigDC Posted October 10, 2009 Author Share Posted October 10, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/177154-variable-and-textbox-color/#findComment-934099 Share on other sites More sharing options...
mikesta707 Posted October 10, 2009 Share Posted October 10, 2009 you would need to pass the variables from PHP to javascript, and you could use the HTML DOM that javascript has built in to dynamically do it. something like //javscript document.getElementById('t1').style.backgroundColor=#CCCCCC Quote Link to comment https://forums.phpfreaks.com/topic/177154-variable-and-textbox-color/#findComment-934101 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.