I have a radio button group in a div, which has a sibling div that contains various textboxes, 4 levels down. If the radio button 'false' is checked, I need to check all the text boxes for that group and if any text box has a value, pop up an alert.
Right now it pops up two alerts for any 'false' radio button regardless of the values in the textboxes. I'm not sure why it doubles the alert for any 'false' radio button, but I am pretty sure it is not actually reading the textboxes.
I am assuming the find() method will look down into multiple levels of children.
EDIT - I should also mention there are 5 questions, so the entire 'question' class is repeated 5 times and when the submit button is clicked, it needs to check each question.
Here is the markup:
<div class="question">
<div class="radio-buttons">
<input type="radio" name="radios" value =" true" />Yes
<input type="radio" name="radios" value =" false" />No
</div>
<div class="label">List out the date, name & category....</div>
<div class="answer-container">
<fieldset class="answer-container-sub">
<div class="answer-group">
<div class="question-label">Name</div>
<div class="question-answer">
<input type="text" />
</div>
<div class="question-label">Name</div>
<div class="question-answer">
<input type="text" />
</div>
</div>
<div class="answer-group">
<div class="question-label">Name</div>
<div class="question-answer">
<input type="text" />
</div>
<div class="question-label">Name</div>
<div class="question-answer">
<input type="text" />
</div>
</div>
</fieldset>
</div>
</div>
<input type="submit" id="button" value="Click Me" />
jQuery ## Editted to change class name in the below code so it matches the above html. ##
$("#button").on("click", function () {
$('input:radio').each(function () {
if ($(this).closest('.radio-buttons').find('input:checked').val() == "False") {
if ($(this).siblings('.answer-container').find('input[type=text]').val() != '') {
alert("You clicked no but a textbox has a value");
}
}
});
});