title: fill input if radio is selected using jquery
body: <p>I have a input and two radio buttons.</p>
  
  <p>The input accepts a number for a time period a person lives at a residence.</p>
  
  <p>The radio buttons are months &amp; years. </p>
  
  <p>I want to fill a 2nd input using the 1st input value (numerical value of length at residence) and either the value for months or years based on the radio selected.</p>
  
  <p>I've made it spit out the time, but it spits out the value for both radio button because I did not have an if statement to check.  I already have jquery in my form and it works.  I just need this small section of my form to work.</p>
  
  <p>My question is, how do I set up the conditional statement for checking what radio is checked?</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;input type="number" value="" required maxlength="5" class="form-control" name="homeLength" id="homeLength"&gt;
  &lt;input type="radio" id="years" value="Years" name="length" required&gt; Years
  &lt;input type="radio" id="months" value="Months" name="length"&gt; Months
  </code></pre>
  
  <p>jQuery</p>
  
  <pre><code>$('#months').click(function () {
    if ($(this).attr("checked") == "checked") {
      $('#homeLength, #months').bind('keypress blur', function () {
        $('#homeTime').val($('#homeLength').val() + ' ' + ' ' + $('#months').val() + ' ' + ' ');
      });
    }
  });
  
  $('#years').click(function () {
    if ($(this).attr("checked") == "checked") {
      $('#homeLength, #years').bind('keypress blur', function () {
        $('#homeTime').val($('#homeLength').val() + ' ' + ' ' + $('#years').val() + ' ');
      });
    }
  });
  </code></pre>