javascript - Get ID of Table Element and open a modal with data with same id -


hy, have following table bootstrap have data php select:

    <div class="table-responsive">          <table class="table table-bordered table-hover">              <tr>                 <th>nome</th>                 <th>cognome</th>                 <th>telefono</th>                 <th>e-mail</th>                 <th>azioni utente</th>             <tr>              <?php                  while($contatto = mysql_fetch_assoc($risultati)) {                      echo "<tr>";                      echo "<td>" .$contatto['nome']. "</td>";                     echo "<td>" .$contatto['cognome']. "</td>";                     echo "<td>" .$contatto['telefono']. "</td>";                     echo "<td>" .$contatto['email']. "</td>";                     echo "<td>                      <a href='#' class='btn btn-primary' data-id='".$id = $contatto['id']."'><span class='glyphicon glyphicon-pencil'></span></a></button>                     </td>";                 }              ?>          </table> </div> 

and clicking on button open me modal:

<div id="mymodal" class="modal fade" style="padding-top:15%; overflow-y:visible;">     <div class="modal-dialog">          <div class="modal-content">              <div class="modal-header">                 <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>                 <h4 class="modal-title custom_align" id="heading">modifica dati contatto</h4>             </div>                  <div class="modal-body">                     <div class="form-group">                         <input class="form-control" type="text" placeholder="nome" value = "<?php echo $row[0]; ?>">                     </div>                     <div class="form-group">                         <input class="form-control" type="text" placeholder="cognome">                     </div>                     <div class="form-group">                         <input class="form-control" type="text" placeholder="riferimento (eventuale)">                     </div>                     <div class="form-group">                         <input class="form-control" type="text" placeholder="numero telefono">                     </div>                     <div class="form-group">                         <input class="form-control" type="text" placeholder="indirizzo e-mail">                     </div>                 </div>                  <div class="modal-footer ">                     <button type="button" class="btn btn-primary btn-lg" style="width: 100%;"><span class="glyphicon glyphicon-ok-sign"></span> modifica contatto</button>                 </div>              </div>             <!-- /.modal-content -->          </div>         <!-- /.modal-dialog -->      </div> 

with javascript:

<script type="text/javascript">     $(document).ready(function(){         $('.btn').click(function(){             //get id             var id = $(this).data('id');             $("#mymodal").modal('show');         });     }); </script> 

i want know best solution open modal values ​​of sql's row same id. in advance suggestions

i use ajax call when button gets pressed. such as:

<script type="text/javascript">  $(document).ready(function() {      $('.btn').click(function() {          //get id          var id = $(this).data('id');          $.ajax({              url: "lookup.php",              data: id,              type: "post",              cache: false,              datatype: "json"          }).done(function(response) {              // error checking, etc.             if (response) {                  $("#mymodal").modal('show');              }           });      });  </script> 

then here if return data database can append them modal using jquery.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -