Ver Mensaje Individual
  #19 (permalink)  
Antiguo 20/03/2010, 15:08
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Como hago para que al pinchar en una linea de una tabla cambie de registro

Hola

No logro ver donde puede estar el error. Te he montado esto que a efectos prácticos es lo mismo que te ocupa

Código PHP:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title></title>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF8">
  6. <style type="text/css">
  7. .color0 {background: orange;}
  8. .color1 {background: yellow;}
  9. </style>
  10. <script type="text/javascript">
  11. function volcar_valores(tabla) {
  12. tr = document.getElementById(tabla);
  13. td = tr.getElementsByTagName('td');
  14. idDiv = document.getElementById('formulario');
  15. inputDiv = idDiv.getElementsByTagName('input');
  16.     for (i = 0; i < td.length; i++) {
  17.         inputDiv[i].value = td[i].innerHTML;       
  18.     }
  19. }
  20. </script>
  21. </head>
  22. <!-- -->
  23. <body>
  24. <table width="100%" border="1px">
  25. <tr>
  26. <th>NOMBRE</th>
  27. <th>DIRECCI&Oacute;N</th>
  28. <th>CIUDAD</th>
  29. <th>C.P.</th>
  30. <th>PROVINCIA</th>
  31. <th>T-MOVIL</th>
  32. </tr>
  33.  
  34. <?php
  35. $tabla = 0;
  36. //----------------------
  37. while ($tabla < 4) {
  38.    
  39.         $resto = ($tabla % 2);
  40.             switch ($resto) { // Coloreamos cada tabla        
  41.                 case 0: $estilo = "color0"; break;        
  42.                 case 1: $estilo = "color1"; break;
  43.             }
  44.  
  45. //-------------------------Fila de un color-------------------------
  46. print ("<tr width='100%' id='$tabla' onclick='volcar_valores($tabla);'>\n");
  47. print ("<td class=".$estilo.">nombre_" .$tabla. "</td>\n");
  48. print ("<td class=".$estilo.">direccion_" .$tabla. "</td>\n");
  49. print ("<td class=".$estilo.">ciudad_" .$tabla. "</td>\n");
  50. print ("<td class=".$estilo.">codigo_" .$tabla. "</td>\n");
  51. print ("<td class=".$estilo.">provincia_" .$tabla. "</td>\n");
  52. print ("<td class=".$estilo.">movil_" .$tabla. "</td>\n");
  53. print ("</tr>\n");
  54. $tabla += 1;
  55.  
  56. }
  57. //------------------------------------------------------
  58. ?>
  59. </table>
  60.  
  61. <!-- Asigno las variables a mi formulario-->
  62. <div id="formulario">
  63. <form action="" method="post">
  64. <div><B>NOMBRE:</B></div>
  65. <input name="nombre" type="text" value="">
  66. <div><B>DIRECCI&Oacute;N:</B></div>
  67. <input name="direccion" type="text" value="">
  68. <div><B>CIUDAD:</B></div>
  69. <input name="ciudad" type="text" value="">
  70. <div><B>C.P:</B></div>
  71. <input name="codigo" type="text" value="">
  72. <div><B>PROVINCIA:</B></div>
  73. <input name="provincia" type="text" value="">
  74. <div><B>T-MOVIL:</B></div>
  75. <input name="moil" type="text" value="">
  76. </form>
  77. </div>
  78. </body>
  79. </html>

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />