Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/05/2011, 09:01
Avatar de anam_1710
anam_1710
 
Fecha de Ingreso: abril-2011
Mensajes: 5
Antigüedad: 13 años
Puntos: 0
Pregunta Hacer select dependiente

Hola
Necesito hacer un select que al seleccionar el producto me cargue en otro select el precio de ese producto.
El código que tengo es el siguiente y el problema es que me carga los productos pero cuando selecciono alguno de ellos, se carga en el select de precio siempre el mismo precio.
Que puedo hacer... donde tengo el erro???

Gracias

<?php
include("conectores.inc");

$mysql_enlace=mysql_connect($servidor,$usuario,$cl ave);
mysql_select_db($bd,$mysql_enlace);
$consulta="SELECT * FROM producto";
$resultado=mysql_query($consulta,$mysql_enlace);
?>
<html>
<head>
<title>.::.</title>
<script language="javascript">
function llenar(cod_producto)
/*{
alert("Campos vacios");
}*/
{
document.agregar.precio.length=0;
document.agregar.precio.options[0]= new Option("Seleccione el Precio"," ","defaultselected");

var indice=0;
<?php
$consultas="SELECT * FROM precio";
$resultados=mysql_query($consultas,$mysql_enlace);

while($registros=mysql_fetch_array($resultados))
{ ?>
if (cod_producto=="<?php echo $registros['id_producto'];?>")
{
document.agregar.precio.options[indice]= new Option("<?php echo$registros['valor'];?>","<?php echo$registros['id_precio'];?>");
indice++;
}
<?php
}
?>
}
</script>
</head>
<body>
<form action="agregaraccion.php" method="post" name="agregar">
Producto
<select name="producto" onchange="llenar(this.value);">

<option value="- - -">- - -</option>
<?php
while($registro=mysql_fetch_array($resultado))
{
echo"<option value='".$registro['codigo_producto']."'>".$registro['Nombre']."</option>";
}
?>
</select>
Precio
<select name="precio">
<option value="- - -">- - -</option>
<?php
while($registro=mysql_fetch_array($resultado))
{
echo"<option value='".$registro['id_precio']."'>".$registro['id_precio']."</option>";
}
?>
</select>
</form>
</body>
</html>