title: Get value from dynamically created checkboxes if checked
body: <p>I made few checkboxes along with a button which on submit calls a function where I want to get all the values of checkboxes which have been checked.</p>
  
  <p>Code for creating those checkboxes is:</p>
  
  <pre><code>for (var loop=0; loop &lt; count; loop++)
  {
  
    var chap  =   document.createElement("input");
    chap.type =   "checkbox";
    chap.value    =   nearby[loop];
    chap.id   =   nearby[loop];
  
    document.getElementById("mapdisplay").appendChild(chap);
    var nearo = nearby[loop];
    var s     =   document.getElementById("mapdisplay");
    var text  =   document.createTextNode(nearby[loop]);
    s.appendChild(text);
    var br        =   document.createElement('br');
    s.appendChild(br);
  }
  </code></pre>
  
  <p>Now I want to retrieve the values which are checked. I am trying this (but to no available)</p>
  
  <pre><code>function fsearch()
  {
      var p       =   x;
      var narr    =   new Array();
      narr=nearby;//a global arr
      var checked_vals = new Array(); 
      $('#mapdisplay input:checkbox:checked').foreach()
  
               {
                checked_vals.push(this.value);
  
               }
  </code></pre>
  
  <p>Please suggest something  to retrieve the checked values <code>id</code> of generated values are in array form. I can not use <code>$("#nearby[0]").val()</code>.</p>