title: How to select radio buttons in jquery
body: <p>The code below adds a value into a textbox:</p>
  
  <pre><code>$('#mainTxtWeight').val(textWeight);
  </code></pre>
  
  <p>But what I want know is how can I select a radio button depending on what a value is using jquery?</p>
  
  <p>Below is the radio buttons:</p>
  
  <pre><code>&lt;table id="replies"&gt;
      &lt;tr&gt;
          &lt;th colspan="2"&gt;Replies&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Number of Replies:&lt;/td&gt;
          &lt;td align="left"&gt;
              &lt;div class="replytd"&gt;
                  &lt;label&gt;
                      &lt;input type="radio" name="reply" id="singlebtn " value="single" class="replyBtn"
                      /&gt;Single&lt;/label&gt;
              &lt;/div&gt;
              &lt;div class="replytd"&gt;
                  &lt;label&gt;
                      &lt;input type="radio" name="reply" id="multiplebtn" value="multiple" class="replyBtn"
                      /&gt;Multiple&lt;/label&gt;
              &lt;/div&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I have created an if statement below, I just need help being able to select "Single" radio button if Reply Type equals "Single", or select "Multiple" radio button if reply Type equals "Multiple".</p>
  
  <p>Below is if statement:</p>
  
  <pre><code>if(reply == "Single") {
      //select "Single" radio button
  } else if(reply == "Multiple") {
      //select "Multiple" radio button
  }
  </code></pre>
  
  <p>I want the exact same thing to occur with this line of code as well which is again "Single" and "Multiple" radio buttons:</p>
  
  <pre><code>var $btnReply = "&lt;input type='radio' name='reply[" + count + "]' value='single' class='replyBtnRow' /&gt; Single&lt;br /&gt;&lt;input type='radio' name='reply[" + count + "]' value='multiple' class='replyBtnRow' /&gt; Multiple";
  
  $replies.children().append($btnReply);
  
  if($("input[name=reply]:checked").length) {
      $replies.find('input[name="reply[' + count + ']"]').eq($("input[name=reply]:checked").val() == "single" ? 0 : 1).prop("checked", true);
  }
  </code></pre>
  
  <p>UPDATE:</p>
  
  <pre><code>function addwindow(reply) { 
  
  
      if($(plusbutton_clicked).attr('id')=='mainPlusbutton') { 
  
          $('input[value="'+reply.toLowerCase()+'"]').attr('checked', true);
          } else { 
              $(plusbutton_clicked).closest('tr').find('input[value="'+reply.toLowerCase()+'"]').attr('checked', true);
              }
  
      $.modal.close(); 
      return false;
  } 
  </code></pre>