title: pass checkbox values to bootstrap modals and calling div modals based on id
body: <p>I'm trying to get the checkbox values into the div modals based on the corresponding button clicks. I'm unable to achieve it. </p>
  
  <p>Desired result: The corresponding buttons should pass the checkbox values in the corresponding modal div and display them.</p>
  
  <p>Thanks in advance.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function(){
  
  var favorite = [];
       $.each($("input[name='sport']:checked"), function() {
        favorite.push($(this).val());
      });
  
  $("button1").click(function() { 
   $("#myModal").modal('show').on('shown.bs.modal', function() {
        $("#checkid").html("I play these games " +"&lt;br&gt;" + favorite.join("&lt;br&gt;"));
      }); 
   });
  $("button2").click(function() {
    $("#myModal2").modal('show').on('shown.bs.modal', function() {
        $("#checkid").html("I dont Play these games " +"&lt;br&gt;" + favorite.join("&lt;br&gt;"));
      }); 
   }); 
  
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="myModal1" class="modal fade" role="dialog"&gt;
    &lt;div class="modal-dialog"&gt;
      &lt;div class="modal-content"&gt;
        &lt;div class="modal-header"&gt;
          &lt;button type="button" class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;
          &lt;h4 class="modal-title"&gt;Modal Header&lt;/h4&gt;
        &lt;/div&gt;
        &lt;div class="modal-body"&gt;
           This are the Games that I usually play, and i'm really go at it:&lt;br&gt;
          &lt;p id="checkid"&gt;&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class="modal-footer"&gt;
          &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div id="myModal2" class="modal fade" role="dialog"&gt;
    &lt;div class="modal-dialog"&gt;
      &lt;div class="modal-content"&gt;
        &lt;div class="modal-header"&gt;
          &lt;button type="button" class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;
          &lt;h4 class="modal-title"&gt;Modal Header&lt;/h4&gt;
        &lt;/div&gt;
        &lt;div class="modal-body"&gt;
          This are the Games that I don't usually play, but would love to:&lt;br&gt;
          &lt;p id="checkid"&gt;&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class="modal-footer"&gt;
          &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;form&gt;
    &lt;h3&gt;Select your favorite sports:&lt;/h3&gt;
    &lt;label&gt;
      &lt;input type="checkbox" value="football" name="sport"&gt; Football&lt;/label&gt;
    &lt;label&gt;
      &lt;input type="checkbox" value="baseball" name="sport"&gt; Baseball&lt;/label&gt;
    &lt;label&gt;
      &lt;input type="checkbox" value="cricket" name="sport"&gt; Cricket&lt;/label&gt;
    &lt;label&gt;
      &lt;input type="checkbox" value="boxing" name="sport"&gt; Boxing&lt;/label&gt;
    &lt;label&gt;
      &lt;input type="checkbox" value="racing" name="sport"&gt; Racing&lt;/label&gt;
    &lt;label&gt;
      &lt;input type="checkbox" value="swimming" name="sport"&gt; Swimming&lt;/label&gt;
    &lt;br&gt;
    &lt;button type="button"&gt;Get Values&lt;/button&gt;
  &lt;/form&gt;
  &lt;button  id = "button1" type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" &gt;I play these games&lt;/button&gt;
    &lt;button  id = "button2" type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal2"&gt;I dont play these games&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>