hola amigos como estan disculpen que haya abierto otro tema respecto a registro de facturas, es qtengo dias intentando de hacer y no logro hacer nada de lo que quiero, aqui consegui un ejemplo y lo adapte a mi necesidad pero tengo un problema de como mostrar el combobox llenado de la bd en las filas que voy agregando dinamicamente con javascript
Código PHP:
Ver original<?php
for ($i=1;$i<=$_POST["var_cont"];$i++)
{
echo "Numero de Fila: " ; echo $i;
echo "Codigo: "; echo $_POST["code_$i"];
echo "Nombre: "; echo $_POST["name_$i"];
echo "Precio: "; echo $_POST["precio_$i"];
echo "Cantidad: "; echo $_POST["cant_$i"];echo "<br>";
}
}
?>
<html>
<head>
<title>PRUEBA AGREGAR FILAS
</title>
</head>
<body>
<form id="form" name="form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onSubmit="asigna()">
<br>
<table border="1" id="tabla" bordercolor="#FFCC33" cellspacing="1">
<tr align="center">
<td colspan="4"><font color="blue" size="1">DETALLE DE FACTURAS </font></td>
</tr>
<tr align="center">
<td><font color="blue" size="1">COD</font></td>
<td><font color="blue" size="1">NOMBRE</font></td>
<td><font color="blue" size="1">PRECIO</font></td>
<td><font color="blue" size="1">CANTIDAD</font></td>
</tr>
<tr>
<td><input type="text" size="4" name="code_1" /></td>
<td><select name="name_1" id="name_1" maxlength="10" onChange="document.getElementById('precio_1').value=this.options[this.selectedIndex].getAttribute('name_1'); actualizar_importe()" required="required"><option value="">-- ELIJE PRODUCTO --</option>
<?php
$row[]=array($r['cod_producto'],$r['producto'],$r['precio']); }
foreach($row as $v){ ?>
<option name_1="<?php echo $v[2] ?>" value="<?php echo $v[0] ?>"><?php echo $v[1] ?></option>
<?php }?>
</select></td>
<td><input type="text" size="8" name="precio_1" id="precio_1"/></td>
<td><input type="text" size="8" name="cant_1"/></td>
<input type="hidden" name="var_cont">
</tr>
</table>
<input type="button" name="b1" value="Agrega Producto" onClick="addRowX()">
<input type="button" name="b2" value="Elimina Producto" onClick="borrar()">
<table border="1" id="tabla_f2" bordercolor="#6B238E" align="center">
<tr>
<td><input type="submit" name="ok" id="ok" value="GUARDAR" /></td>
</tr>
</table>
</form>
</body>
</html>
<script language='JavaScript'>
var cont=1;
function addRowX() //Esta la funcion que agrega las filas :
{
cont++;
var indiceFila=1;
myNewRow = document.getElementById('tabla').insertRow(-1);
myNewRow.id=indiceFila;
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<td><input type="text" size="4" name="code_'+cont+'" /></td>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<select name="name_'+cont+'"/></select>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<input type="text" size="8" name="precio_'+cont+'"/>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<input type="text" size="8" name="cant_'+cont+'"/>';
indiceFila++;
}
//////////////Borrar() ///////////
function borrar() {
var table = document.getElementById('tabla');
if(table.rows.length > 3)
{
table.deleteRow(table.rows.length -1);
cont--;
}
}
////////////FUNCION ASIGNA VALOR DE CONT PARA EL FOR DE MOSTRAR DATOS MP-MOD-TT////////
function asigna()
{
valor=document.form.var_cont.value=cont;
}
</script>