title: javascript changing radio button value based on user selection
body: <p>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: </p>
  
  <p>Question 39: Yes must be selected if Yes is selected for one of questions 41 - 45. Otherwise, it's No. </p>
  
  <p>Question 40: Yes must be selected if Yes is selected for ALL of questions 41-45. Otherwise it's No. </p>
  
  <p>This is what I have: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function CBR() {
    for ($i = 41; $i &lt; 46; $i++) {
      if ($('input[name=' + $i + '][id=Yes]').checked == true) {
          $('input[name=39][id=Yes]').click();
      }
    }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;td width="66px"&gt;
    &lt;input type="radio" id="Yes" name="&lt;?php echo $question['id']; ?&gt;" value="1" onClick="CBR()"&gt;Yes&lt;/td&gt;
  
  &lt;td width="66px"&gt;
    &lt;input type="radio" id="No" name="&lt;?php echo $question['id']; ?&gt;" value="0"&gt;No&lt;/td&gt;
  
  &lt;td width="66px"&gt;
    &lt;input type="radio" id="NA" name="&lt;?php echo $question['id']; ?&gt;" value="1" checked="true"&gt;N/A&lt;/td&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>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?</p>
  
  <p>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. </p>