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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change DIV style on the fly? 1

Status
Not open for further replies.

Albion

IS-IT--Management
Aug 8, 2000
517
US
I have a <SELECT> tag with 5 color options. I also have a <DIV> in the same file as the <SELECT>. I would like to change the background-color: style of the <DIV> when the color is selected in the <SELECT> box without having to refresh the page. Can anyone help me out?

Thanks

-Craig
 
forum216

Anyway at its most basic:

Code:
function Change_Color(myselect,thediv){

thediv.style.backgroundColor=myselect.value;
}

HTML:
<select name="myselect" onChange="Change_Color(this,document.getElementById('thediv'));">
<option value="#FFFFFF">White</option>
<option value="#000000">Black</option>
<option value="#FF0000">Red</option>
...
</select>

<div id="thediv">The background color of this div will change</div>


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks, that's exactly what I needed.

-Craig

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top