I am new to javascript and facing a challenge. Whenever I update the list items in an HTML example from engineer, pilot, technician, if I select engineer, there should be an onchange event calling a function in JavaScript that shows a hidden select list containing the division he works in, like wing or engine division.
This is the JavaScript code:
<script type="text/javascript">
function func(v) {
if(v=="Engineer"){
var y=document.getElementById("a");
y.style.visibility = "visible";
}
}
</script>
This is the HTML code:
<select onchange="func(this.value)">
<option>Please Select</option>
<option value="Engineer">Engineer</option>
<option value="Pilot">Pilot</option>
<option value="Technician">Technician</option>
</select>
Below is my hidden select list in HTML that should display when 'Engineer' is selected:
<select id="a" style="visibility : hidden">
<option>select the division</option>
<option>Wing Division</option>
<option>Engine Division</option>
</select>
I seem to have a mistake in my JavaScript code, can anyone please assist me?