title: Get Checkbox total count & save value in textbox if checked
body: <p>I have written below code to get a total count of Checked chechbox and save the value checked value comma separated in textbox.</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;label class='checkbox-inline'&gt;&lt;input type='checkbox' class='checkbox-btn' value='1' onchange='checkCount(this.value);'&gt;&lt;/label&gt;
  &lt;label class='checkbox-inline'&gt;&lt;input type='checkbox' class='checkbox-btn' value='2' onchange='checkCount(this.value);'&gt;&lt;/label&gt;
  &lt;label class='checkbox-inline'&gt;&lt;input type='checkbox' class='checkbox-btn' value='3' onchange='checkCount(this.value);'&gt;&lt;/label&gt;
  
  &lt;input type="text" name="proId" id="proId"&gt;
  </code></pre>
  
  <p><strong>JS:</strong></p>
  
  <pre><code>function checkCount(elm) {
    var cheCount = $(":checkbox:checked").length;
    document.getElementById('selectCount').innerHTML = cheCount;
  
    definVal = document.getElementById('proId').value ;
    var inval = elm+","+definVal;
    document.getElementById('proId').value = inval;
  
    if(cheCount==0){
      document.getElementById('proId').value = "";
    }
  }
  </code></pre>
  
  <p>Check the output in below image:
  <a href="https://i.stack.imgur.com/e5U5U.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e5U5U.jpg" alt="enter image description here"></a></p>
  
  <p>My issue is that, when i unchecked the checkbox, its value is adding in textbox instead of getting remove.</p>