Welcome to WebmasterWorld Guest from 34.201.121.213

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?


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

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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 3, 2005
posts:1585
votes: 0


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