I have an application with several hidden divs. When a checkbox is checked, the div is shown with another checkbox to show another hidden div. There are three hidden divs in total and the last div (obviously) does not contain this checkbox.
I am using the following script:
$(function () {
$("#isApplicant2").click(function () {
$("#b2").fadeToggle(500);
});
$("#isApplicant3").click(function () {
$("#b3").fadeToggle(500);
});
$("#isApplicant4").click(function () {
$("#b4").fadeToggle(500);
});
})
HTML
<div class="form-group">
@Html.Label("Is there another Applicant?", new { @class = "col-md-3" })
<div class="col-md-2">
@Html.CheckBox("isApplicant2")
</div>
</div>
<div id="b2" style="display: none">
<div> Some Content </div>
</div>
<div class="form-group">
@Html.Label("Is there another Applicant?", new { @class = "col-md-3" })
<div class="col-md-2">
@Html.CheckBox("isApplicant3")
</div>
</div>
<div id="b3" style="display: none">
<div> Some Content </div>
</div>
<div class="form-group">
@Html.Label("Is there another Applicant?", new { @class = "col-md-3" })
<div class="col-md-2">
@Html.CheckBox("isApplicant4")
</div>
</div>
<div id="b4" style="display: none">
<div> Some Content </div>
</div>
I've got it working with one shortcoming (a major one) that I cannot quite figure out how to cure. If the first div toggle (#isApplicant2) is false, I need to set all others to false as well and the same for each following. So that #isApplicant2 cannot be false yet display other hidden divs.
I have searched high and low but am just getting lost on the concept of .unbind if that is even the right way.