In my code, for every child class, there's a checkbox used to display it, otherwise it's not displayed. When one of the checkbox (var inputs) is checked or unchecked, this function is called. The child class associated with the checkbox will be displayed. Now, I want all the inputs inside the child class to be required. I've looked a bit but could not find how to do it.
JS:
$(".displayChildBtn").change(function(){
var inputs = $("form .displayChildBtn");
var childClasses = $("form .childClass");
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].checked == true) {
childClasses[i].style.display = "block";
//need to have all inputs inside childClasses[i] required
}
else {
childClasses[i].style.display = "none";
}
}
})
HTML (this section is repeated in the form but with different inputs inside the childClass):
<input type="checkbox" class="displayChildBtn" name="AddSomeone"/>//when checked, shows the childClass and should place the inputs required.
<label for="AddSomeOne">Add Someone</label>
<div class="chilClass">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname">
</div>
To be more clear, what I want is that when the checkbox is checked, the inputs of the childClass right next to it become required. I dont know how to properly select these inputs. Thank you