Foros del Web » Programando para Internet » PHP »

selects dependientes

Estas en el tema de selects dependientes en el foro de PHP en Foros del Web. HOLA QUIEN ME PUEDE COLABORAR CON ESTE CÓDIGO.. TENGO DOS TABLAS UNA DE PRODUCTOS Y OTRA DE PRECIOS. EN LA DE PRODUCTOS TENGO: id_producto, Nombre, ...
  #1 (permalink)  
Antiguo 26/04/2011, 10:02
Avatar de anam_1710  
Fecha de Ingreso: abril-2011
Mensajes: 5
Antigüedad: 13 años
Puntos: 0
Pregunta selects dependientes

HOLA QUIEN ME PUEDE COLABORAR CON ESTE CÓDIGO..
TENGO DOS TABLAS UNA DE PRODUCTOS Y OTRA DE PRECIOS.
EN LA DE PRODUCTOS TENGO:
id_producto, Nombre, id_precio
Y EN LA DE PRECIOS TENGO:
id_precio, valor
CUANDO VOY AL NAVEGADOR ME CARGA LOS DOS SELECTS, PERO CUANDO SELECCIONO EL PRODUCTO, SOLO ME APARECE UN PRECIO EN EL SELECT DE PRECIOS... NO SE DONDE PUEDA ESTAR EL ERROR...
EL CODIGO QUE TENGO ES EL SIGUIENTE:

<?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['cod_precio']."'>".$registro['valor']."</option>";
}
?>
</select>
</form>
</body>
</html>
  #2 (permalink)  
Antiguo 26/04/2011, 10:11
Avatar de skiper0125  
Fecha de Ingreso: octubre-2010
Ubicación: $this->Mexico('Toluca');
Mensajes: 1.127
Antigüedad: 13 años, 6 meses
Puntos: 511
Respuesta: selects dependientes

Que tal anam_1710

el problema de los select dependientes lo recomiendo que lo realices con ajax ya que tiene mayor funcionalidad. checa este link:
http://www.formatoweb.com.ar/ajax/se...pendientes.php
y en base a esto lo puedes adaptar a tu aplicacion

Saludos
__________________
Recuerda que estamos aquí para orientarte, y no para hacer tu trabajo.
Si mi aporte fue de ayuda, recuerda que agradecer no cuesta nada +1

Skiper0125

Etiquetas: dependientes, selects
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 02:53.