Hide Div on Select
by Otobong Okoko
HTML
<select id="getFname" onchange="intCheck(this);">
<option value="1">Personal Loans</option>
<option id="optState" value="2">Asset Finance</option>
</select>
<div id="StateOpt" style="display:none;">
<div class="row">
<div class="col-md-6">
<div class="form-group g-mb-20">
<!--<input class="form-control g-brd-gray-light-v5 g-bg-gray-light-v5 g-bg-gray-light-v5--focus g-px-10 g-py-12" aria-label="Address" type="text" name="callupno" placeholder="NYSC Call-Up Number" required>-->
<label for="interest">Your Current State
<select class="form-control g-brd-gray-light-v5 g-bg-gray-light-v5 g-bg-gray-light-v5--focus g-px-10 g-py-12" aria-label="Address">
<option value="" selected>Select a State</option>
<option value="1">Abia</option>
<option value="2">Abuja</option>
<option value="3">Adamawa</option>
<option value="4">Akwa Ibom</option>
<option value="5">Anambra</option>
<option value="6">Bauchi</option>
<option value="7">Bayelsa</option>
<option value="8">Benue</option>
<option value="9">Borno</option>
<option value="10">Cross river</option>
<option value="11">Delta</option>
...
JavaScript
function intCheck(nameSelect)
{
if(nameSelect){
stateOptValue = document.getElementById("optState").value;
if(stateOptValue == nameSelect.value){
document.getElementById("StateOpt").style.display = "block";
}
else{
document.getElementById("StateOpt").style.display = "none";
}
}
else{
document.getElementById("StateOpt").style.display = "none";
}
}