title: How to dynamically check/uncheck html checkbox by JavaScript
body: <p>I know that several questions about this topic have been asked, but I was unable to find an answer for my case.</p>
  
  <p>I have a checked <code>checkbox</code> as</p>
  
  <pre><code>&lt;input type="checkbox" name="text" checked="checked" /&gt;
  </code></pre>
  
  <p>I need to send ajax request by checking/unchecking, but I do not know what can be the reliable (with browser compatibility) for an <code>if statement</code> such as</p>
  
  <pre><code>if (this.value == 'on')
  {
  this.value = 'off';
  ajax call;
  }
  else
  {
  this.value ='on';
  ajax call;
  }
  </code></pre>
  
  <p>Note that the value is not important here, and we need to catch <code>checked/unchecked</code>, but how control the checked element by <code>JavaScript</code> when the html original element has <code>checked="checked"</code>?</p>
  
  <p>If using <code>checked</code> instead of <code>value</code> as</p>
  
  <pre><code>if (this.checked == true)
  {
  this.checked = false;
  ajax call;
  }
  else
  {
  this.checked =true;
  ajax call;
  }
  </code></pre>
  
  <p>The tick of <code>checkbox</code> will not be changed in the browser (always ticked).</p>