Ver Mensaje Individual
  #28 (permalink)  
Antiguo 23/04/2009, 06:15
Avatar de colote
colote
 
Fecha de Ingreso: julio-2008
Ubicación: Rosario - Santa Fe - Argentina
Mensajes: 729
Antigüedad: 15 años, 9 meses
Puntos: 8
Respuesta: Select dinamico

Hola gente !!!
Perdon que me meta !!!!
Aca les dejo como lo hago yo, menu desplegable tomado desde la base de datos y vuelva los datos en casillas inputs !!!

Código PHP:
<?php
include ('conexion.php');

if(isset(
$_POST['ok'])){

//Pones un boton ok y da de alta, modificas, o borras o lo que desees !!!
}


?>

<html>
<head>
<script type="text/javascript">
function lista_cli(lista){

document.form.codin.value = lista.options[lista.selectedIndex].value; 
document.form.cod_cli.value = lista.options[lista.selectedIndex].text; 
document.form.razon_soc.value = lista.options[lista.selectedIndex].getAttribute("alt");
document.form.domicilio.value = lista.options[lista.selectedIndex].getAttribute("alt1");
document.form.cp.value = lista.options[lista.selectedIndex].getAttribute("alt2");
document.form.localidad.value = lista.options[lista.selectedIndex].getAttribute("alt3");
}
</script>

<?php
///////Creamos el selector Clientes de la BDD ///////
$varc="";
$resump=mysql_query("select * from clientes order by cod_cli",$conexion);

while (
$row_cli=mysql_fetch_array($resump))

$varc.= '<option value="'.$row_cli["cod_cli"].'" 
alt="'
.$row_cli["razon_soc"].'",
alt1="'
.$row_cli["domicilio"].'",
alt2="'
.$row_cli["codigo_postal"].'",
alt3="'
.$row_cli["localidad"].'"
>'
.$row_cli["cod_cli"].'</option>';
}
?>

</head>


<body>
<form id="form" name="form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" >

<table id="izq" align="center" cellspacing=1 cellpadding=0>

<tr><td><b>Cliente:</b></td></tr>
<tr>
<td><select name="lista_c" onChange="lista_cli(this)">
<option value="option">Select</option>
<?echo $varc?>
</select>
</td>
<td><input type="hidden" size="2"  name="codin"></td>
<td><input type="text" size="2"  name="cod_cli"></td>
<td><input type="text" size="40"  name="razon_soc"></td>
<td><input type="text" size="30"  name="domicilio" ></td>
<td><input type="text" size="6"  name="cp"></td>
<td><input type="text" size="20"  name="localidad"></td>
</tr>
</table>
</form>

</body>
</html>
__________________
Mail: [email protected]