Ver Mensaje Individual
  #5 (permalink)  
Antiguo 19/08/2008, 07:49
Avatar de colote
colote
 
Fecha de Ingreso: julio-2008
Ubicación: Rosario - Santa Fe - Argentina
Mensajes: 729
Antigüedad: 16 años, 7 meses
Puntos: 8
Respuesta: Como Agregar Filas , que incluye un <Select> e inputs

Hola Avatar08, gracias por tus ideas, te cuento que las filas las agrega, pero en la lista desplegable no muestra las opciones :S, hay algo que no esta bien, pero no se que podra ser.
Aca dejo el codigo completo, para que se vea mejor y el link con el codigo actualizado.

Código PHP:
<?php
$conexion
=mysql_connect("localhost","root","000000") or die("Problemas en la conexion");
mysql_select_db("empresa",$conexion) or die("Problemas en la selección de la base de datos");

if(isset(
$_POST['ok'])){
$nombre=array($_POST['name']);
$unidad=array($_POST['unid']);
$cant_mp=array($_POST['cant_mp']);
$desperdicio=array($_POST['desperdicio']);
$cos_mp_pesos=array($_POST['cos_mp_pesos']);
$cos_mp_dolar=array($_POST['cos_mp_dolar']);
$sub_mp_pesos=array($_POST['sub_mp_pesos']);
$sub_mp_dolar=array($_POST['sub_mp_dolar']);


foreach (
$nombre as $nombre1){ 
    foreach (
$unidad as $unidad1){ 
        foreach (
$cant_mp as $cant_mp1){ 
            foreach (
$desperdicio as $desperdicio1){ 
                foreach (
$cos_mp_pesos as $cos_mp_pesos1){ 
                    foreach (
$cos_mp_dolar as $cos_mp_dolar1){
                        foreach (
$sub_mp_pesos as $sub_mp_pesos1){ 
                            foreach (
$sub_mp_dolar as $sub_mp_dolar1){  
                            echo 
"<PRE>";print_r ($nombre1); echo "</PRE>";}
                        echo 
"<PRE>";print_r ($unidad1); echo "</PRE>";}
                    echo 
"<PRE>";print_r ($cant_mp1); echo "</PRE>";}
                echo 
"<PRE>";print_r ($desperdicio1); echo "</PRE>";}
            echo 
"<PRE>";print_r ($cos_mp_pesos1); echo "</PRE>";}
        echo 
"<PRE>";print_r ($cos_mp_dolar1); echo "</PRE>";}
    echo 
"<PRE>";print_r ($sub_mp_pesos1); echo "</PRE>";}
echo 
"<PRE>";print_r ($sub_mp_dolar1); echo "</PRE>";}

}


?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>PRUEBA FORO</title>

<script language='JavaScript'>

function addRow()
{
var indiceFilaFormulario=1;
myNewRow = document.getElementById('tabla').insertRow(-1);
myNewRow.id=indiceFilaFormulario;

myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<td><select name="lista" id="lista" onChange="listaSeleccionada(this)"><option value="option">Seleccionar</option><?echo $var?></select></td>';

myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<td><input type="text" size="5"  name="code[]" id="code" disabled/></td>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<input type="text" size="25" name="name[]" id="name" value=""/>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<input type="text" size="7" name="unid[]" id="unid" value=""/>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<input type="text" size="7" name="cant_mp[]" id="cant_mp" value="cant"/>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<input type="text" size="7" name="desperdicio[]" id="desperdicio" value="desp"/>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<input type="text" size="7" name="cos_mp_pesos[]" id="cos_mp_pesos" value=""/>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<input type="text" size="7" name="cos_mp_dolar[]" id="cos_mp_dolar" value=""/>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<input type="text" size="7" name="sub_mp_pesos[]" id="sub_mp_pesos" value="<?php echo $sub_mp_pesos;?>"/>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<input type="text" size="7" name="sub_mp_dolar[]" id="sub_mp_dolar" value="<?php echo $sub_mp_dolar;?>"/>';


indiceFilaFormulario++;
}

function borra()
{
  var nparrafo=document.getElementById('tabla');
  nparrafo.removeChild(nparrafo.lastChild);
}


function listaSeleccionada(lista) {  

document.form.code.value = lista.options[lista.selectedIndex].value; 
document.form.name.value = lista.options[lista.selectedIndex].text; 
document.form.unid.value = lista.options[lista.selectedIndex].getAttribute("alt");
document.form.cos_mp_pesos.value = lista.options[lista.selectedIndex].getAttribute("alt1");
document.form.cos_mp_dolar.value = lista.options[lista.selectedIndex].getAttribute("alt2");

}
 
</script>
</head>
<body>

<form id="form" name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border ="1" id="tabla" color ="0000ff" bordercolor="#FFCC33">
<font color="1166FF"><h4>MATERIA PRIMA</h4></font>
<tr>
<td>
<select name="lista" id="lista" onChange="listaSeleccionada(this)">
    <option value="option">Seleccionar</option>
<?php
$resump
=mysql_query("select * from materia_prima order by codigo",$conexion);
$sub_mp_pesos=10;
$sub_mp_dolar=20;
while (
$row1=mysql_fetch_array($resump))
       {  
$var"<option value='".$row1["codigo"]."' 
                     alt='"
.$row1["unidad"] ."',
                    alt1='"
.$row1["costo_mp_pesos"] ."',
                    alt2='"
.$row1["costo_mp_dolar"] ."'> 
                    "
.$row1["nombre"]."</option>";
echo 
$var;


?>
</select></td>

<td><input type="text" size="5"  name="code[]" id="code" disabled/></td>
<td><input type="text" size="25" name="name[]" id="name" /></td>
<td><input type="text" size="7"  name="unid[]" id="unid" /></td>
<td><input type="text" size="7"  name="cant_mp[]" id="cant_mp" value="Cantidad" /></td>
<td><input type="text" size="7"  name="desperdicio[]" id="desperdicio" value="Desperdicio"/></td>
<td><input type="text" size="7"  name="cos_mp_pesos[]" id="cos_mp_pesos" /></td>
<td><input type="text" size="7"  name="cos_mp_dolar[]" id="cos_mp_dolar" /></td>
<td><input type="text" size="7"  name="sub_mp_pesos[]" id="sub_mp_pesos" value="<?php echo $sub_mp_pesos;?>" /></td>
<td><input type="text" size="7"  name="sub_mp_dolar[]" id="sub_mp_dolar" value="<?php echo $sub_mp_dolar;?>"/></n><br></td>

<td><input type="button" name="boton2" value="(M)" onClick="addRow()"></td>
<td><input type="button" name="borrar" value="[-]" onClick="borra()"></td>
</table>
    

<td><input type="submit" name="ok" id="ok" value="OK" /></td>
<td><input type="submit" value="VOLVER"></td>
<hr>
</form>
</body>
</html>
Gracias
__________________
Mail: [email protected]