title: Disable input on check/uncheck of checkbox
body: <p>I have 2 checkboxes and 2 input tags for mail and phone.</p>
  
  <p>My requirement is such that I want to disable the input of phone when I check mail and vice-versa. But on checking both the checkboxes I want to keep both the inputs enabled.</p>
  
  <p>Here's my <a href="http://jsfiddle.net/myphpontest/rhr43g4m/" rel="nofollow">fiddle</a>. This is the code which is not working on the fiddle as I've never used it before. But it is working on my localhost.</p>
  
  <p>The problem is, it's not working well when I check both boxes and then check-unchek many times.</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;input type="checkbox" id="check_email" name="check_email" onchange="disablePhone()" /&gt; Email
  &lt;input type="checkbox" id="check_phone" name="check_phone" onchange="disableEmail()" /&gt; Phone
  </code></pre>
  
  <p><br>
  
  </p>
  
  <p><strong>Script</strong></p>
  
  <pre><code>var chk_mail = 0;
  var chk_phone = 0;
  var unchk = 0;
  
  function disablePhone()
  {
      if(unchk == 1)
      {
          document.getElementById("ref_email").disabled = true;
          unchk = 0;
          //alert("disablePhone")
      }
      if(chk_mail == 0 &amp;&amp; unchk == 0)
      {
          if(document.getElementById("check_email").checked == true)
          {
              document.getElementById("form-field-phone").disabled = true;
              chk_mail = 1;
          }
      }
      else if( chk_mail == 1 &amp;&amp; unchk == 0)
      {
          document.getElementById("check_email").checked = false;
          document.getElementById("form-field-phone").disabled = false;
          chk_mail = 0;
      }
      if(chk_phone ==1 &amp;&amp; chk_mail == 1)
      {
          document.getElementById("ref_email").disabled = false;
          document.getElementById("form-field-phone").disabled = false;
          chk_phone = 0;
          unchk = 1;
      }
  }
  
  function disableEmail()
  {
      if(unchk == 1)
      {
          document.getElementById("form-field-phone").disabled = true;
          unchk = 0;
          //alert("disableEmail")
      }
  
      if(chk_phone == 0 &amp;&amp; unchk == 0)
      {
          if(document.getElementById("check_phone").checked == true)
          {
              document.getElementById("ref_email").disabled = true;
              chk_phone = 1;
          }
      }
      else if(chk_phone == 1 &amp;&amp; unchk == 0)
      {
          document.getElementById("check_phone").checked = false;
          document.getElementById("ref_email").disabled = false;
          chk_phone = 0;
      }
      if(chk_phone ==1 &amp;&amp; chk_mail == 1)
      {
          document.getElementById("ref_email").disabled = false;
          document.getElementById("form-field-phone").disabled = false;
          chk_phone = 0;
          unchk = 1;
      }       
  }
  </code></pre>