Ver Mensaje Individual
  #2 (permalink)  
Antiguo 31/05/2016, 03:55
Avatar de xfxstudios
xfxstudios
 
Fecha de Ingreso: junio-2015
Ubicación: Valencia - Venezuela
Mensajes: 2.448
Antigüedad: 8 años, 10 meses
Puntos: 263
Respuesta: como puedo pasar variables a una ventana modal

Yo lo haría de esta manera:

Código PHP:
Ver original
  1. <table cellpadding="10" cellmargin="5" border="1">
  2.     <tr>
  3.         <th>Cod</th>
  4.         <th>Cedula</th>
  5.         <th>Nombre</th>
  6.         <th>Apellido</th>
  7.         <th>Programa</th>
  8.         <th>Carrera</th>
  9.         <th>Opciones</th>
  10.     </tr>
  11.     <?php
  12.     foreach($model as $row)
  13.     {
  14.         ?>
  15.         <tr>
  16.         <td><input type="hidden" name="cod" id="cod<?php echo $row['cod'] ?>" value="<?php echo $row['cod'] ?>" /></td>
  17.         <td><input type="text" name="cedula" id="ced<?php echo $row['cod'] ?>" value="<?php echo $row['cedula'] ?>" /></td>
  18.         <td><input type="text" name="nombre" id="nom<?php echo $row['cod'] ?>" value="<?php echo $row['nombre'] ?>" /> </td>
  19.         <td><input type="text" name="apellido" id="ape<?php echo $row['cod'] ?>" value="<?php echo $row['apellido'] ?>" /></td>
  20.         <td><input type="text" name="programa" id="pro<?php echo $row['cod'] ?>" value="<?php echo $row['programa'] ?>" /></td>
  21.         <td><input type="text" name="carrera" id="car<?php echo $row['cod'] ?>" value="<?php echo $row['carrera'] ?>" /></td>
  22.         <td><button type="button" id="<?php echo $row['cod'] ?>" onClick="datos(this.id); openVentana();">Editar</button><button type="button" onClick="window.location='eliminar.php?cod=<?php echo $row['cod'] ?>' ">Eliminar</button></td>
  23.         </tr>
  24. <?php
  25.     }
  26. ?>
  27. </table>
  28.         <br>
  29.         <br>
  30. <div>
  31. <?php
  32. $pagination->pages("btn");
  33. ?>
  34. </div>
  35.     </center>
  36.  
  37.  
  38. <div class="ventana" id="inicio">
  39.     <div class="formedi" >
  40.         <div class="cerrar"><a href="javascript:closeVentana();"><img height='20px' width='20px' src="./imagenes/close.png"></a></div>
  41.         <h3>Editar Usuarios</h3>
  42.  
  43. <form action="actualizar.php" method="post">
  44. <input type="hidden" name="cod" id="cod_mod" value="" />
  45. <br><br>
  46. <label> Cedula: </label>
  47. <input type="text" name="cedula" id="ced_mod" value="" />
  48. <br>
  49. <br>
  50. <label> Nombre: </label>
  51. <input type="text" name="nombre" id="nom_mod" value="" />
  52. <br>
  53. <br>
  54. <label> Apellido: </label>
  55. <input type="text" name="apellido" id="ape_mod" value="" />
  56. <br>
  57. <br>
  58. <label> Programa: </label>
  59. <input type="text" name="programa" id="pro_mod" value="" />
  60. <br>
  61. <br>
  62. <label> Carrera: </label>
  63. <input type="text" name="carrera" id="car_mod" value="" />
  64. <br>
  65. <br>
  66. <br>
  67. <input type="submit" value="actualizar">
  68. </form>
  69.  
  70.         </div>
  71.     </div>
  72. </div>
  73.  
  74.  
  75. <table class="pie">
  76.     <tr>
  77.         <td class="pieletra" align="middle"> Copyright © 2016 | PNF Informatica Nocturno.
  78.         <br>Todos los Derechos Reservados.</td>
  79.     </tr>
  80. </table>


Código Javascript:
Ver original
  1. function datos(X){
  2.  
  3.         document.getElementById('cod_mod').value = $("#cod"+X).val();
  4.         document.getElementById('ced_mod').value = $("#ced"+X).val();
  5.         document.getElementById('nom_mod').value = $("#ced"+X).val();
  6.         document.getElementById('ape_mod').value = $("#ape"+X).val();
  7.         document.getElementById('pro_mod').value = $("#pro"+X).val();
  8.         document.getElementById('car_mod').value = $("#car"+X).val();
  9.     }





Muestra funcionando: http://codepen.io/anon/pen/EyaxBK

Claro no abre el modal por obvias razones, pero verás como se copian los datos en los campos a los que corresponde. Saludos
__________________
[email protected]
HITCEL