In my javascript program I have created two select boxes and When the first option in the select box is selected,I want to display a selection of 3 images name in the images select box. When the second option is selected, I want to display a selection of corresponding 3 images name in the images box. For that I did below coding. but it's not working. can anyone help me to solve ?
code:
<!DOCTYPE html>
<html>
<head>
<title>selectbox</title>
<style>
div.event {
padding-left: 40%;
padding-top: 5%;
}
#mySelect{
width: 60px;
height: 50px;
text-align: center;
}
</style>
</head>
<body>
<form name="myForm">
<div class="event">
<select id="mySelect" multiple size="3" onchange="myFunction()">
<option value="name" disabled="disabled">Name</option>
<option value="animals">Animals</option>
<option value="flowers">Flowers</option>
</select>
<select id="mySelect2" multiple size="4">
<option disabled="disabled">Images</option>
</select>
</div>
</form>
<script>
var selectbox2 = document.getElementById('mySelect2');
function myFunction() {
if (document.getElementById('mySelect').value == "Animals"){
selectbox2.append('<option>Tiger</option>');
selectbox2.append('<option>Lion</option>');
selectbox2.append('<option>Bear</option>');
}
else if (document.getElementById('mySelect').value == "Flowers"){
selectbox2.append('<option>Rose</option>');
selectbox2.append('<option>Lotus</option>');
selectbox2.append('<option>Lily</option>');
}
}
</script>
</body>
</html>