title: Working with a checkbox in a jquery dialog
body: <p>I have a jquery dialog that uses a non-jquery javascript function to complete the functioning depending upon which button is selected. I have added a checkbox within the dialog that the user must check to signify understanding of what will happen.</p>
  
  <p>When I add the testing of the checked state to the non-jquery javascript, the checked state is always returned as false.</p>
  
  <p>Following is the code. The first two alerts and the return statement are for testing:</p>
  
  <pre><code>function acceptPitch()
  {
  
      // the two alerts and return false are for testing only
      alert('jq=' + $('#understand').prop("checked"));
      alert('checkbox=' + document.getElementById('understand').checked);
      return false;
      if (document.getElementById('understand').checked)
      {
          handleUserDelay();
          $('#decision').val('yes');
          document.forms['cancellationForm'].submit();
          return true;
      }
      else
      {
          alert('[appropriate message here]');
          return false;
      }
  }
  </code></pre>
  
  <p>If the checkbox is not in the dialog box, the above function works as expected. But when it is placed inside the dialog box, the tests for "checked" always return false.</p>
  
  <p>Here is the main code for the dialog:</p>
  
  <pre><code>var $dialog_cancel = $('#rh-dialog.cancel');
  $dialog_cancel.dialog(
  {
      autoOpen:false,
      width:500,
      modal:true,
      draggable:true,
      resizable:false
  });
  
  $('#reason').change(function()
  {
      var reason1 = $(this).val().substr(0,1);
      if (reason1 == 'n')
      {
          $('#pitch').html($('#pitch-no').html());
          $('#acceptPitchButton').val($('#free-button-text').html());
      }
      else if (reason1 == 'y')
      {
          $('#pitch').html($('#pitch-yes').html());
          $('#acceptPitchButton').val($('#perp-button-text').html());
      }
      else
      {
          validCancelReason();
      }
  });
  
  $('#requestCancelButton').click(function()
  {
      if (validCancelReason())
      {
          $dialog_cancel.dialog('open');
      }
  });
  </code></pre>
  
  <p>The following is markup taken from a "view source" listing. Please note that jquery is used to only display two of the last four divs, and that some other adjustments are made by the jquery:</p>
  
  <pre><code>&lt;div id="rh-dialog" class="cancel" title="Confirm Cancellation"&gt;
      &lt;p&gt;
          This will request cancellation of your continuing subscription service.&lt;br /&gt;
      &lt;/p&gt;
      &lt;div id="pitch"&gt;&lt;/div&gt;
      &lt;p style="font-style: italic; margin-top:10px;"&gt;
          Please click &lt;strong&gt;YES!&lt;/strong&gt; to continue your plan, or &lt;strong&gt;No, Thank You&lt;/strong&gt; to cancel.
      &lt;/p&gt;
      &lt;div&gt;
          &lt;div id="rh-dialog-button-1"&gt;
              &lt;input type="button" id="acceptPitchButton" value="Don't Cancel"  onclick="bar1.showBar(); acceptPitch();" /&gt;
          &lt;/div&gt;
          &lt;div id="rh-dialog-button-2"&gt;
              &lt;input type="button" id="rejectPitchButton" value="No, Thank You, Just Cancel" onclick="bar1.showBar(); rejectPitch();" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="pitch-no" class="no-disp"&gt;&lt;strong&gt;GET ONE FREE MONTH!&lt;/strong&gt;&lt;br /&gt;It is very important to us that all of our subscribers have success with our service, not only in speaking with reps but in actually growing your business. Given you are canceling because you were unsatisfied, we would like to offer you &lt;strong&gt;one FREE month.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;To take advantage of this offer simply click &lt;strong&gt;Yes! Free Month&lt;/strong&gt; and your credit card or PayPal account will not be charged for the next month.&lt;br /&gt;&lt;br /&gt;After your free month, you can choose to cancel your subscription or continue on with our Maintenance plan.&lt;br/&gt;&lt;br/&gt;&lt;form id="agree-form"&gt;&lt;input type="checkbox" id="understand"&gt;&lt;strong&gt;I understand&lt;/strong&gt; that by requesting a free month I am not canceling my subscription, and that after the free month is over, my credit card or PayPal account will be charged for the next month of service and again every month thereafter until I do cancel.&lt;/input&gt;&lt;/form&gt;&lt;/div&gt;
  &lt;div id="pitch-yes" class="no-disp"&gt;&lt;strong&gt;BARGAIN PRICE PERPETUITY PLAN!&lt;/strong&gt;&lt;br /&gt;You realize that placing quality sales reps requires a continual effort trolling for reps at all times because timing is of the essense. For that reason, we would like to offer you our &lt;strong&gt;Perpetuity Plan&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;This plan is only USD $79/month, cancel anytime, and you can lock into that rate for life.&lt;br /&gt;&lt;br /&gt;Click &lt;strong&gt;Yes! Perpetuity Plan&lt;/strong&gt; to switch to the Perpetuity Plan.&lt;/div&gt;
  &lt;div id="free-button-text" class="no-disp"&gt;Yes! Free Month - Continue Subscription&lt;/div&gt;
  &lt;div id="perp-button-text" class="no-disp"&gt;Yes! Perpetuity Plan&lt;/div&gt;
  </code></pre>
  
  <p>In addition, I am adding a screen shot:</p>
  
  <p><a href="https://i.stack.imgur.com/aNeEO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aNeEO.png" alt="screen shot showing dialog with checkbox"></a><br>
  <sub>(source: <a href="http://www.oofdah.com/wp-content/uploads/2012/04/Screen-Shot-2012-04-27-at-4.38.13-PM.png" rel="nofollow noreferrer">oofdah.com</a>)</sub>  </p>