apologies for the large code, still a newbie and i was working on this prior, the initial javascript code i was helped with worked to show contents of the first div when you select YES, I naively thought if i duplicated it, it would work for the NO, well...it did, but both are showing at the same time.
How can the code be written such that when i click yes it shows (#current_school_details) and when i click No it shows (#current_school_details_two) and replaces or hides the yes option rather than both sitting there.
function selectFunction() {
var yes = document.getElementById("gridRadios1");
var current_school_details = document.getElementById("current_school_details");
if (document.querySelector(".form-check-input").checked === true) {
current_school_details.style.display = "none";
} else {
current_school_details.style.display = "block";
}
}
function selectFunctionTwo() {
var no = document.getElementById("gridRadios2");
var current_school_details_two = document.getElementById("current_school_details_two");
if (document.querySelector(".form-check-input").checked === true) {
current_school_details_two.style.display = "none";
} else {
current_school_details_two.style.display = "block";
}
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" >
<div>
<legend class="col-form-label col-sm-12 pt-0">Are you currently a Twyford student?*</legend>
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" type="radio" name="gridRadios" id="gridRadios1" value="option1" onclick="javascript:selectFunction();">
<label class="form-check-label" for="gridRadios1"> Yes </label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="gridRadios" id="gridRadios2" value="option2" onclick="javascript:selectFunctionTwo();">
<label class="form-check-label" for="gridRadios2"> No </label>
</div>
</div>
</div>
<div id="current_school_details">
<h2>Current School Details</h2>
<select class="form-control">
<option>--select--</option>
<option>Twyford CofE High School</option>
<option>Ealing Fields High School</option>
<option>William Perkin CofE High School</option>
</select>
</div>
<br>
<div id="current_school_details_two">
<h2>Current School Details</h2>
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputCity">Current School*</label>
<input type="text" class="form-control" id="inputCity">
</div>
<div class="form-group col-md-6">
<label for="inputCity">School Address*</label>
<input type="text" class="form-control" id="inputCity">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputCity">Office Email*</label>
<input type="text" class="form-control" id="inputCity">
</div>
<div class="form-group col-md-6">
<label for="inputCity">Current Head of Year*</label>
<input type="text" class="form-control" id="inputCity">
</div>
</div>
</div>
</fieldset>