Send a value to the modal

0

I have a table with several employees and it counts the plate of each hum.  

I created a modal that when the manager clicks on the employee's name is called a modal where you can enter the number of the plate.  

Reason: there are situations that this plate number can change.  

Please try again later.  

How do I when I click on the table I can store the employee's plate that was clicked so I can update the table?

Here are my codes:

  

Modal script:

<script type="text/javascript">
      $(document).ready(function(){
        $("a[rel=modal]").click( function(ev){
          ev.preventDefault();

          var id = $(this).attr("href");

          var alturaTela = $(document).height();
          var larguraTela = $(window).width();

          //colocando o fundo preto
          $('#mascara').css({'width':larguraTela,'height':alturaTela});
          $('#mascara').fadeIn(1000); 
          $('#mascara').fadeTo("slow",0.8);

          var left = ($(window).width() /2) - ( $(id).width() / 2 );
          var top = ($(window).height() / 2) - ( $(id).height() / 2 );

          $(id).css({'top':top,'left':left});
          $(id).show(); 
        });

        $("#mascara").click( function(){
          $(this).hide();
          $(".window").hide();
        });

        $('.fechar').click(function(ev){
          ev.preventDefault();
          $("#mascara").hide();
          $(".window").hide();
        });
      });
    </script>

    <style type="text/css">

    .window{
      display:none;
      width:300px;
      height:300px;
      position:absolute;
      left:0;
      top:0;
      background:#FFF;
      z-index:9900;
      padding:10px;
      border-radius:10px;
    }

    #mascara{
      position:absolute;
        left:0;
        top:0;
        z-index:9000;
        background-color:#000;
        display:none;
    }

    .fechar{display:block; text-align:right;}

    </style>
  

My table:

  <?php
     $query_pesquisa = mysql_query("SELECT 
       func_chapa AS CODIGO,
       func_nome  AS NOME 
       FROM 
            funcionarios 
            WHERE
                 func_status='1'")or die(mysql_error());    
    if (empty($query_pesquisa)) {
    echo "Nenhum registro encontrado.";
    }
    ?>
  <table  class='datatable table table-hover table-bordered table-responsiv'>
   <thead>
     <tr>
        <th>CODIGO</th>
        <th>NOME</th>
     </tr>
    </thead>
  <?php
     echo"<tbody>";   
     while ($row = mysql_fetch_array($query_pesquisa)) {
     echo" <tr>";
        echo"<td>".$row['CODIGO']."</td>";
        echo"<td><a href='#usuario' rel  ='modal'>".$row['NOME']."</a></td>";
     echo" </tr>";

   }   
  echo"  </tbody>";
 echo" </table>";



?>
  

Modal:

<div class="window" id="usuario">
      <a href="atualiza.php" class="fechar">X Fechar</a>
      <h4>ATUALIZA CHAPA:</h4>
      <center><form  action="atualizar.php" method="POST">
        <label for="chapa">CHAPA:</label>
        <input type="text" name="chapa" id="chapa">
        <br />
        <br />
          <button type="submit" class="btn btn-primary">ATUALIZAR</button>
      </form>
      </center>
    </div>

    <!-- mascara para cobrir o site --> 
    <div id="mascara"></div>
    
asked by anonymous 20.05.2016 / 23:44

1 answer

1

use it this way

Link table

   <a href="#"  id="botfun" data-id="<?echo $id_funcionario?>"  
   title="Editar">Fulanp</span></a>

Modal

 <script>
 $("table").on('click',"#btncli", function(){
 var idfone = $(this).attr('data-id');  // pega o id do botão

 $.post('formulario.php', {acao: 'alterar',idfone: idfone},   
 function(retorno){
    $("#modalcli").modal({ backdrop: 'static' });
    $("#cli").html(retorno);        
});

 });
  </script>

   <div class="modal drag" id="modalcli" tabindex="-1" role="dialog" aria-  labelledby="" aria-hidden="true">
  <div class="modal-dialog">
    <div>
       <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-  hidden="true">&times;</button>
            <h3 class="modal-title">Solicita&ccedil;&atilde;o de   Cancelamento</h3>
        </div>

        <div class="modal-body">
            <p>
        <div id="cli">
        </div></p>
   </div></div></div></div></div>   

form.php

  <?php
  $id_funcionario = filter_input(INPUT_POST, 'idfone',   
  FILTER_SANITIZE_NUMBER_INT); 
  ?>
    <h4>ATUALIZA CHAPA:</h4>
  <center><form  action="atualizar.php" method="POST">
    <label for="chapa">CHAPA:</label>
    <input type="text" name="chapa" id="chapa">
    <br />
    <br />
      <button type="submit" class="btn btn-primary">ATUALIZAR</button>
  </form>
    
22.05.2016 / 05:41