I am trying to display a green, yellow, or red dot image depending on what color the user selects. I based my code on something I found on this question.
For some reason, the function is not working. Currently nothing happens when the user makes a selection.
var statusCode = document.getElementById('statusCode');
var greenDot = document.getElementById('greenDot');
var yellowDot = document.getElementById('yellowDot');
var redDot = document.getElementById('redDot');
function myfunction() {
if (statusCode.value == 'Green') {
greenDot.style.display = 'circle';
yellowDot.style.display = 'none';
redDot.style.display = 'none';
}
else if (statusCode.value == 'Yellow') {
greenDot.style.display = 'none';
yellowDot.style.display = 'circle';
redDot.style.display = 'none';
}
else if (statusCode.value == 'Red') {
greenDot.style.display = 'none';
yellowDot.style.display = 'none';
redDot.style.display = 'circle';
}
}
<select id="statusCode" onload="myFunction()">
<option value="Green">Green</option>
<option value="Yellow">Yellow</option>
<option value="Red">Red</option>
</select>
<p>
<img src="http://clipart-library.com/image_gallery/156788.png" style="display: none;" id="greenDot">
<img src="http://www.clker.com/cliparts/o/b/y/x/Z/c/yellow-dot-md.png" style="display: none;" id="yellowDot">
<img src="http://www.clker.com/cliparts/s/o/v/c/T/Y/red-dot-md.png" style="display:none;" id="redDot">
</p>