Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/07/2016, 07:28
Avatar de edrc5
edrc5
 
Fecha de Ingreso: marzo-2016
Mensajes: 16
Antigüedad: 8 años, 1 mes
Puntos: 0
Almacenar tabla dinamica en variables de session

Saludos foristas,

Tengo una duda en como almacenar en variables de session php, los valores de varios inputs text de una tabla creada a partir de filas (Inputs) que se crean mediante una función javascript. Tengo el siguiente código
Código:
<form id="form" name="form" method="post" action="pagina1.php">

<div class="col-md-3 inline-block">
<article>
     <table id="Tabla" border="1">
<thead>
	<tr>
		<th colspan="3" class="color-titulo center" style="text-align: center;"><font color="FFFFFF">Factor1</font></th>
	</tr>
</thead>
 <tr>
          	   <td><input type="checkbox" name="chk" value="chk"/></td>
               <td><input type="text" name="txt" value="" /></td>
          </tr>

     </table>
     <p></p>
     <p class="inline-block">
  <input type="button" value="Agregar" onclick="agregarFila('Tabla');" style="width:100px"/>
  </p>
  <p class="col-md-5 inline-block">
<input type="button" value="Borrar" onclick="borrarFila('Tabla');" style="width:100px"/>
</p>
</article>
</div>
<div class="col-md-4 inline-block">
<article>
<table id="Tabla1" border="1" >
<thead>
	<tr>
		<th colspan="3" class="color-titulo center" style="text-align: center;"><font color="FFFFFF">Factor 2</font></th>
	</tr>
</thead>
          <tr>
          	   <td><input type="checkbox" name="chk1"/></td>
               <td><input type="text" name="txt1" value="" /></td>
          </tr>

     </table>
     <p></p>
     <p class="inline-block">
<input type="button" value="Agregar" onclick="agregarFila('Tabla1');" style="width:100px"/>
</p>
<p class="col-md-5 inline-block">
<input type="button" value="Borrar" onclick="borrarFila('Tabla1');" style="width:100px"/>
</p>
</article>

<center>
<input type="submit" id="Siguiente" name="Siguiente" value="Siguiente" style="width:100px"/>
</form>
<input type="submit" onclick= "location.href='index.php'" id="Atras" name="Atras" value="Atrás" style="width:100px"/>
</center>
En el código anterior se van creando filas al dar clic al boton Agregar, lo que quiero es que a medida que voy agregando filas, estos se vayan almacenando en variables de session php (Arrays), para poder imprimirlo o mostrarlo en la pagina siguiente pagina1.php


Este es el cogido javascript que tengo para agregar y borrar filas:
Código:
function agregarFila(tablaID) {

               var tabla = document.getElementById(tablaID);

 

               var contarFila = tabla.rows.length;

               var fila = tabla.insertRow(contarFila);

 

               var celda1 = fila.insertCell(0);

               var elemento1 = document.createElement("input");

               elemento1.type = "checkbox";

               celda1.appendChild(elemento1);



               var celda2 = fila.insertCell(1);

               var elemento2 = document.createElement("input");

               elemento2.type = "text";

               celda2.appendChild(elemento2);

          }


          function borrarFila(tablaID) {

               try {

               var tabla = document.getElementById(tablaID);

               var contarFila = tabla.rows.length;

 

               for(var i=0; i<contarFila; i++) {

                    var fila = tabla.rows[i];

                    var chkbox = fila.cells[0].childNodes[0];

                    if(null != chkbox && true == chkbox.checked) {

                         tabla.deleteRow(i);

                         contarFila--;

                         i--;

                    }

               }

               }catch(e) {

                    alert(e);

               }

          }
Estoy atento a sus comentarios.

Saludos y gracias de antemano.