title: Javascript : function bind.click & for each checkbox
body: <p>I have some combo box, every combo box have value and group by class &amp; ID</p>
  
  <pre><code>&lt;input type="checkbox" value="A" class="box-1" id="ID_1"&gt;
  &lt;input type="checkbox" value="B" class="box-1" id="ID_1"&gt;
  &lt;input type="checkbox" value="C" class="box-2" id="ID_2"&gt; 
  &lt;input type="checkbox" value="D" class="box-2" id="ID_2"&gt;
  </code></pre>
  
  <p>If user click button, then check each box, if this checked, store value &amp; ID to variable.</p>
  
  <p>EDIT :</p>
  
  <p>JS :</p>
  
  <pre><code>$('#button').bind('click', function() {
  
  var box = '';
  var p =0;
  var count = document.getElementById("count").value; // for count total class checkbox 
  
  for(d=1; d &lt;= count; d++){
  
      p = 0;
      $('.box-' + d).each(function(item){ // each box-1/2/3
          if(this.checked){
              if(p == 0)
              {
                  var name = this.value.replace(/\s/g, '');
                  box += '&amp;' + ($(this).attr('id')) + '=' + '&amp;' + encodeURIComponent(name).toLowerCase());
                  p+=1;
                  alert(box);
              }
              else
              {
                  var href = ($(this).attr('id')) + '=';
                  var name_2 = this.value.replace(/\s/g, '');
                  box += href + '&amp;' + encodeURIComponent(name_2).toLowerCase());
                  p+=1;
              }       
          }
      });
  }
  
  alert(box);
  //location = url;
  });
  </code></pre>
  
  <p>example case :
  the <code>checked</code> combo box is <code>A &amp; D</code>
  what i expect is <code>&amp;ID_1=&amp;AID_2=&amp;D</code> ( this is different ID), if same ID = <code>&amp;ID_1=&amp;A&amp;D</code></p>
  
  <p>when i try alert it's display nothing(''), but when i try alert(box) inside if( p== 0) it's have result <code>1&amp;ID_1=A</code> and <code>0&amp;ID_2=&amp;D</code>.</p>
  
  <p>Try check this <a href="https://jsfiddle.net/Blackarch/c8ue0d3d/5/" rel="nofollow">here</a></p>