title: How to define action on button that is generated dynamically?
body: <p>I am getting the data retrieved from the database and displaying it in a  tag, I am trying to capture the primary key from the database as the value of the button using java script. How do i do this ?</p>
  
  <p>I have tried this using the javascript with in while loop and outside while loop and failed.   <code>while ($row = mysqli_fetch_assoc($records)) {}</code></p>
  
  <pre><code>&lt;?php
      while ($row = mysqli_fetch_assoc($records)) {
  ?&gt;
  &lt;div class="col-lg-4 "&gt;
      &lt;div class="card" style="width:22rem;"&gt;
      &lt;div class="card-body" &gt;
          &lt;!--  &lt;div class="card" style="width: 25rem;height: 30rem;background-color:OFFWHITE ;"&gt;
             &lt;p class="card-text" &gt;--&gt; &lt;label&gt;Customer Name:&lt;/label&gt;
                  &lt;?php echo $row['Name'];?&gt;&lt;br&gt;
                      &lt;label&gt;Phone Number:&lt;/label&gt;
                  &lt;?php echo $row['phoneno'];?&gt;&lt;br&gt;
                      &lt;?php $ticketid = $records['ticketid']; ?&gt;
              &lt;form method="post"&gt;
                  &lt;select class="form-control" name="status"&gt;
                  &lt;option value="Open" selected&gt;Open&lt;/option&gt;
                  &lt;option value="Pending"&gt;Accept&lt;/option&gt;
                  &lt;option value="Reject"&gt;Reject&lt;/option&gt;
                  &lt;/select&gt;
                  &lt;button id="ticket" value="&lt;?php echo $row['ticketid'];?&gt;" onclick="myFunction()" class="btn"&gt;Submit&lt;/button&gt;       
              &lt;/form&gt; 
          &lt;!-- &lt;/p&gt; --&gt;
          &lt;/div&gt;
      &lt;/div&gt; 
  &lt;/div&gt;
  &lt;?php
  }
  ?&gt;
  
  &lt;script&gt;
                  function myFunction(){
                  var ticketid =  "&lt;?php echo $records['ticketid'];?&gt;";
                  var x = document.getElementById("ticket").value;
                  alert(x);
  
                  //alert(ticketid);
                  //echo $status;
                  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I want to capture the primary key of each data displayed on the div, which is in card view. How do i do it?</p>