I need to create a js that can select radio buttons based on the values of radio buttons the user clicks. The conditions are the following:
Question 39: Yes must be selected if Yes is selected for one of questions 41 - 45. Otherwise, it's No.
Question 40: Yes must be selected if Yes is selected for ALL of questions 41-45. Otherwise it's No.
This is what I have:
function CBR() {
for ($i = 41; $i < 46; $i++) {
if ($('input[name=' + $i + '][id=Yes]').checked == true) {
$('input[name=39][id=Yes]').click();
}
}
}
<td width="66px">
<input type="radio" id="Yes" name="<?php echo $question['id']; ?>" value="1" onClick="CBR()">Yes</td>
<td width="66px">
<input type="radio" id="No" name="<?php echo $question['id']; ?>" value="0">No</td>
<td width="66px">
<input type="radio" id="NA" name="<?php echo $question['id']; ?>" value="1" checked="true">N/A</td>
What I know the code does as of now is that it checks if any one of 41-45 is selected yes, and if so, it selects Yes for 39. I was just testing to see if this worked and it doesn't look like it, so I can't really move forward. Can anyone help?
To clarify: I have used document.getElementbyID, but if I do, I can't refer to the question number in the js, which is the "name" in html.