Foros del Web » Programando para Internet » Javascript »

filas e input tpe text indefinidos

Estas en el tema de filas e input tpe text indefinidos en el foro de Javascript en Foros del Web. Que tal amigos. Necesito crear un formulario (que ya lo tengo) dentro de un tabla y que pueda agreagar filas e input type text segun ...
  #1 (permalink)  
Antiguo 07/05/2009, 15:29
 
Fecha de Ingreso: noviembre-2008
Mensajes: 21
Antigüedad: 15 años, 5 meses
Puntos: 0
filas e input tpe text indefinidos

Que tal amigos.
Necesito crear un formulario (que ya lo tengo) dentro de un tabla y que pueda agreagar filas e input type text segun la necesidad del usuario
y tambien necesito saber como agregar filas a la tabla sin que se pierda la información que ya capturó el usuario.

algo asi:

| Fecha del Depósito | Numero de ficha | Banco | [+] [-]

|________________|______________|_______| <----- si el usuario desea agreagar un nuevo registro solo de click en [+] y se creee otra fila con los mismos 3 input type text
Estos input deben manejarse con diferente nombre para despues dentro de un ciclo for meterlos a una tabla en una BD

Agradeceré infinitamente su ayuda
  #2 (permalink)  
Antiguo 07/05/2009, 15:41
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: filas e input tpe text indefinidos

Lo de agregar las filas con hacer clic en el [+] lo puedes hacer con Javascript.
Y para diferenciar las filas, puedes usar los nombres de los input tipo array:

<input type="text" name="foo[]" />
<input type="text" name="foo[]" />

Para recorrer los valores, solamente seria hacer un bucle:
foreach($_POST['foo'] as $key => $value) {
//blah blah blah
}
  #3 (permalink)  
Antiguo 07/05/2009, 16:00
 
Fecha de Ingreso: noviembre-2008
Mensajes: 21
Antigüedad: 15 años, 5 meses
Puntos: 0
Respuesta: filas e input tpe text indefinidos

El problema es que no soy muy bueno con el javascript y he encontrado una funcion javascript navegando por la web mira:
ya lo probe y si funciona el detalle es que el nombre del objeto (input) no cambia
entonces los valores al momento de meterlos en la BD siguen siendo los mismos del primer input.

<table border="0" id="base" width="100%">
<tr class="celda">

<td width="20%" style="padding:3px;"></font>Cuenta</td>
<td width="20%" style="padding:3px;"></font>Producto</td>
<td width="15%" style="padding:3px;">Fecha de compra</td>
<td width="15%" style="padding:3px;">Cantidad</td>
<td width="30%" style="padding:3px;">&nbsp;</td>
<td>
<input type="button" class="boton" value="[+]" onClick="addNewRow(event)" alt="Adicionar">&nbsp;
<input type="button" class="boton" value="[-]" onClick="removeLastRow(event)" alt="Remover">
</td>
</tr>
<tr id="example" class="celda">

<td>
<input id='account_name1' size="10" name='456' type='text'></td>

<td style='padding:3px;'><input id='123' size="10"name='product_name1' type='text' ></td>

<td>
<select class="combo" name="operator[]" id="opera">
<option value="January">Enero</option>
<option value="January">Febrero</option>
<option value="in">Marzo</option>
<option value="notin">Abril</option>
<option value="notin">Mayo</option>
<option value="Diciembr">Junio</option>
<option value="in">Julio</option>
<option value="notin">agosto</option>
<option value="Diciembr">Septiembre</option>
<option value="in">Octubre</option>
<option value="notin">Noviembre</option>
<option value="">Diciembre</option>

</select>
</td>
<td>
<input name="values[]" type="text" size="10" id="value">
<input type="hidden" name="btnAction" value="next">
</td>
<td>&nbsp;</td>
</tr>
</table>

<script type="text/javascript" language="JavaScript">

function addNewRow(){
var TABLE = document.getElementById("base");
var TROW = document.getElementById("example");

var content = TROW.getElementsByTagName("td");
var newRow = TABLE.insertRow(-1);
newRow.className = TROW.attributes['class'].value;
insertLOselect(content,newRow);

var newRow2 = TABLE.insertRow(-1);
newRow2.className = TROW.attributes['class'].value;
//window.alert(nueva fila);
//window.alert(content);
copyRow(content,newRow2);
}
function removeLastRow() {
var TABLE = document.getElementById("base");
if(TABLE.rows.length > 2) {
TABLE.deleteRow(TABLE.rows.length-1);
TABLE.deleteRow(TABLE.rows.length-1);
}
}

function appendCell(Trow, txt) {
var newCell = Trow.insertCell(Trow.cells.length)
newCell.innerHTML = txt
}

function copyRow(content,Trow) {
var cnt = 0;
for (; cnt < content.length; cnt++) {
appendCell(Trow, content[cnt].innerHTML);
}
}

function insertLOselect(content,Trow) {
var cnt = 0;
for (; cnt < content.length-1; cnt++) {
appendCell(Trow, '&nbsp;');
}
}
</script>
  #4 (permalink)  
Antiguo 07/05/2009, 17:22
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: filas e input tpe text indefinidos

Tema trasladado desde PHP
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:04.