Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting background color of select box

Status
Not open for further replies.

rmagan

Programmer
Jun 3, 2003
35
US
I have a select box that is dynamically getting its options from the database. I have created a function that changes the BG color of the select box when the option value is changed. This works fine.

When the page is displayed, I want to initially set the BG color of the select box depending on the value from the database. How can I do this?


<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function getColor(p_param_id) {
theSelect = document.getElementById(p_param_id)
theColor = theSelect.options[theSelect.selectedIndex].value
theSelect.style.backgroundColor = theColor.substr(1, theColor.length)
}
</SCRIPT>

<SELECT name=&quot;p_att_status&quot; id=&quot;p_param1&quot; onChange=&quot;getColor(this.id)&quot;>'
<OPTION value=.WHITE>Present
<OPTION value=*RED>Absent
</SELECT>

 
looks good-

try

<body onLoad=&quot;getColor('p_param1')&quot;>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top