title: Populate modal form with jquery
body: <p>I am having orders table drawn from database into datatables(jquery plugin).
  I am having add payment at every last td or every tr. The question is, how do i get the order id of the row in which the addpayment button was clicked to add payment.</p>
  
  <p>Secondly, when the addpayment is clicked, it pops up a modal form with a field or order#. I want populate that field with the order id found in the td and make it not editable or hide it but will be posted to server when the modal form is submitted.</p>
  
  <p>the table and the modal form display well.</p>
  
  <p>this is the table.</p>
  
  <pre><code>&lt;div id="buyorders" class="tab-pane fade " &gt;
      &lt;h3&gt; BUY ORDERS&lt;/h3&gt;
        &lt;div  class="table-responsive col-sm-10"&gt;          
            &lt;table id="buyorderstable" class = "table table-responsive table-striped display" cellspacing="0" width="100%"&gt;   
                 &lt;thead&gt;
                    &lt;tr&gt;
                       &lt;th&gt;ORDER#&lt;/th&gt;
                       &lt;th&gt;DATE&lt;/th&gt;
                       &lt;th&gt;E-CURRENCY&lt;/th&gt;
                       &lt;th&gt;USD&lt;/th&gt;
                       &lt;th&gt;GHC&lt;/th&gt;
                       &lt;th&gt;STATUS&lt;/th&gt;
                       &lt;th&gt;ACTION&lt;/th&gt;
                    &lt;/tr&gt;
                 &lt;/thead&gt;
  
                 &lt;tbody&gt;
  
                 &lt;?php 
  
                  $user_id = "SELECT id FROM user WHERE email ='".$_SESSION["email"]."'";
  
                  $query_user_ref = mysqli_query($mysqli,$user_id)or die('Error: ' . mysqli_error($mysqli));
                  $fetch_user_ref = mysqli_fetch_array($query_user_ref);
                  $user_ref = $fetch_user_ref['id'];
                  $sql = "SELECT * FROM buy_orders WHERE user_ref = '".$user_ref."' "; 
                  $sql_query = mysqli_query($mysqli,$sql)or die('Error: ' . mysqli_error($mysqli));;
  
                  while ($row = mysqli_fetch_array($sql_query)){
                    echo '
                    &lt;tr&gt;
                       &lt;td data-id=".$row["buy_order_no"]." class="orderid" &gt;'.$row['buy_order_no'].'&lt;/td&gt;
                       &lt;td&gt;'.$row['date'].'&lt;/td&gt;
                       &lt;td&gt;'.$row['ecurrency'].'&lt;/td&gt;
                       &lt;td&gt;'.$row['usd'].'&lt;/td&gt;
                       &lt;td&gt;'.$row['ghc'].'&lt;/td&gt;
                       &lt;td &gt;'.$row['status'].'&lt;/td&gt;
                       &lt;td id="addpaylink"&gt; &lt;a href="#"&gt;&lt;i class="fa fa-eye" aria-hidden="true"&gt;View &lt;/i&gt;&lt;/a&gt; &lt;a href="#"  data-toggle="modal" data-target="#myModal"" &gt;ADD PAYMENT&lt;/a&gt;  &lt;/td&gt;
                    &lt;/tr&gt;' ;
                  }
  
                  mysqli_close($mysqli);
                  ?&gt;
  
                  &lt;/tbody&gt;
              &lt;/table&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>this is the modal form</p>
  
  <pre><code>&lt;div class="modal fade" id="myModal" role="dialog"&gt;
  &lt;div class="modal-dialog"&gt;
  
    &lt;!-- Modal content--&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;Add Payment Details&lt;/h4&gt;
        &lt;hr/&gt;&lt;br&gt;
  
      &lt;div id="modaladdpay" class="modal-body"&gt;
        &lt;form method="post" action="user.php"&gt;  
          &lt;div class="form-group"&gt;
                &lt;label for="ORDER#"&gt;ORDER#:&lt;/label&gt;
                &lt;input type="number" name="orderno" class="form-control" id="buyghc" placeholder="Please Specify ORDER# " required&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
                &lt;label for="amount"&gt;Amount in GHC:&lt;/label&gt;
                &lt;input type="number" step="any" name="addpayghc" class="form-control" id="buyghc" placeholder="Enter Amount Sent" required&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
            &lt;label for="payment method"&gt;Select Payment Method:&lt;/label&gt;
               &lt;select class="form-control" name="addpayselect" id="addpayment" required&gt;
                  &lt;option&gt; &lt;/option&gt;
                  &lt;option   value="mobmoney"&gt;Mobile Money&lt;/option&gt;
               &lt;/select&gt;
  
  
              &lt;div class="form-group " id=""&gt;
                &lt;label for="select network"&gt;Select Network:&lt;/label&gt;
                &lt;select name="addpaynettype" class="form-control" required&gt;
                      &lt;option&gt; &lt;/option&gt;
                      &lt;option value="MTN"&gt;MTN&lt;/option&gt;
                      &lt;option value="TIGO"&gt;TIGO&lt;/option&gt;
                      &lt;option value="AIRTEL"&gt;AIRTEL&lt;/option&gt;
                      &lt;option value="VODAFONE"&gt;VODAFONE&lt;/option&gt;
                   &lt;/select&gt;
              &lt;/div&gt;
              &lt;div class="form-group " id=""&gt;
                &lt;label for="Transaction ID"&gt;Transaction ID:&lt;/label&gt;
                &lt;input type="text" name="transid" class="form-control" placeholder="Enter Transaction ID (or Reference Number for Tigo Cash) " required&gt; 
              &lt;/div&gt;
  
              &lt;button type="submit" name="addpaydetails" id="addpaydetails" class="btn btn-primary btn-lg btn-block btn-success " &gt;ADD PAYMENT&lt;/button&gt;
          &lt;/div&gt;
          &lt;/form&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;
  </code></pre>
  
  <p>
    </p>
  
  <p>this is the jquery</p>
  
  <pre><code>$(document).ready(function () {
  $('#myMoal').modal({
      keyboard: true,
      backdrop: "static",
      show:false,
  
  }).on('show', function(){
        var getIdFromRow = $(event.target).closest('tr').find(".orderid").data('id');
      //make your ajax call populate items or what even you need
      $(this).find('#modaladdpay').html($( getIdFromRow) //
  });
  </code></pre>
  
  <p>});</p>