You should probably bind this logic to the onchange event of the selection itself, and not to the click event of individual parameters:
var myDiv = document.getElementById("myDiv");
document.getElementById("mySelect").onchange = function(){
myDiv.style.display = (this.selectedIndex == 0) ? "block" : "none";
}
When we link it this way, we donβt need to mix our HTML and our Javascript. Our HTML may look as simple as the following:
<select id="mySelect" name="values">
<option>0</option>
<option>1</option>
<option>2</option>
</select>
<div id="myDiv">
<p>Select 0 to show me, otherwise I'm invisible!</p>
</div>
Online demo: http://jsbin.com/ijogi
source
share