I am trying to make a click on a drop down menu item reveal hidden element (hidden with CSS). When clicking on the drop down, there are 3 items. One is showing the user that it is a required field. The other two are the main items.
Any help with this would be most appreciated!
Here is the JSfiddle: link
HTML
<p>
<label for="service"><b>Service Type</b></label> <br id="resBr" />
<select name="service" id="service">
<option value="null">Required</option>
<option onclick="show(1)" value="airTransfer">Airport Transfer</option>
<option onclick="show(2)" value="hourly">Hourly</option>
</select>
</p>
<div id="content1" class="content" hidden>
<p>
<label for="airline"><b>Airline</b></label> <br id="resBr" /> <input type="text" name="airline" id="airline"> <br id="resBr" /><br id="resBr" />
<label for="flight"><b>Flight Number</b></label> <br id="resBr" /> <input type="text" name="flight" id="flight"> <br id="resBr" /><br id="resBr" />
<label for="landing"><b>Landing Time</b></label> <br id="resBr" /> <input type="text" name="landing" id="landing">
</p>
</div>
<div>
<p id="content2" class="content" hidden>
<label for="occasion"><b>Occasion</b></label> <br id="resBr" /> <input type="text" name="occasion" id="occasion"> <br id="resBr" /><br id="resBr" />
<label for="start"><b>Pickup Time</b></label> <br id="resBr" /> <input type="text" name="start" id="start"> <br id="resBr" /><br id="resBr" />
<label for="end"><b>Drop Off Time</b></label> <br id="resBr" /> <input type="text" name="end" id="end"><br id="resBr" /><br id="resBr" />
<label for="pickup"><b>Pickup Address</b></label> <br id="resBr" /> <input type="text" name="pickup" id="pickup"><br id="resBr" /><br id="resBr" />
<label for="hours"><b>Total Hours</b></label> <br id="resBr" /> <input type="text" name="hours" id="hours">
</p>
</div>
CSS
#content1 {
color: blue;
}
#content2 {
color: green;
}
.hidden {
display: none;
}
JS
function show(id) {
var allDivs = document.getElementsByClassName('content');
for (var i = 0; i < allDivs.length; i+){
allDivs[i].classList.add('hidden');
}
document.getElementById('content' + id).classList.remove('hidden');
}
hiddenis outside the quotes for class.<br/>and<hr/>, they're just<br>and<hr>now (parsers are in fact instructed to throw away the "self-closing" slash, because HTML is expressly not XML, so "self closing" doesn't mean anything.<img>,<link>,<input>and friends shouldn't have a "self-closing" slash)