Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

JavaScript change class with select form

11:56 pm on Feb 22, 2012 (gmt 0)

New User

5+ Year Member

joined:Aug 30, 2009
posts: 1
votes: 0

How can I change the class of a div(myBox) from a select form using JavaScript?

<style type="text/css">
.red {background:#FF0000;color:#FFF}
.white {background:#FFF;color:#000}
.blue {background:#0000FF;color:#FFF}

<form id="myform" action="#">
<select id="bgcolor">
<option value="red">Red</option>
<option value="white">White</option>
<option value="blue">Blue</option>

<div id="myBox" class="red">This is myBox</div>
12:37 pm on Feb 23, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 3, 2005
votes: 0

<select id="bgcolor" onchange="document.getElementById('myBox').className=this.value" >