hola!!
alguien sabe como puedo hacerle para que al seleccionar un elemento de una lista desplegable, esta devuelva un parametro en php en relacion a una bd...por ejemplo: al seleccionar algun codigo postal, los correspondientes textbox muestren la localidad,estado,pais....lo estaba haciendo asi...
<?
session_start();
?>
<?
if (!isset($_SESSION['admin']))
{
echo"<script language='javascript' type='text/javascript'>
alert('Acceso Denegado')
window.location='index.php'
</script>";
exit();
}
?>
<!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=iso-8859-1" />
<title>Ingresar Clientes</title>
<script language="javascript" type="text/javascript">
function m(){
validarCliente();
document.form1.cp2.value=document.form1.cp.value;
break;
document.form1.submit()
}
</script>
<link href="plantillas/Copia de computerstyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?
$vusuario=$_SESSION['admin'];
include ("conexion.php");
$conecction=conectar();
echo "<form id='form1' name='form1' method='post' action='registrar clientes2.php'>
<table width='500' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td><label>Usuario</label></td>
<td><label><input name='logincli' type='text' size='10' maxlength='10' />
</label></td>
</tr>
<tr>
<td>Contraseña</td>
<td><label>
<input name='contra' type='password' size='40' maxlength='60' />
</label></td>
</tr>
<tr>
<td>Nombre</td>
<td><label>
<input name='nombre' type='text' size='40' maxlength='60'></textarea>
</label></td>
</tr>
<tr>
<td>Mail</td>
<td><label>
<input name='correo' type='text' size='40' maxlength='60'/>
</label></td>
</tr>
<tr>
<td>Direccion</td>
<td><label>
<input name='direccion' type='text' size='40' maxlength='60' />
</label></td>
</tr>
<tr>
<td>Telefono</td>
<td><label>
<input name='telefono' type='text' size='40' maxlength='60' />
</label></td>
</tr>
<tr>
<td>Codigo Postal</td>
<td>
<label>
<select name='cp' onChange='m();'>";
$sql3="select * from lugares";
$vquery=mysql_query($sql3,$conecction);
while ($vfeob=mysql_fetch_object($vquery)){
echo"<option value='$vfeob->cp'>$vfeob->cp </option>";
}
echo"
</select>";echo"<input type='text' name='cp2' />
</label></td>
</tr>
<tr>
<td>Ciudad</td>
<td>
<input type='text' name='cd' value='' />
</td>
</tr>
<tr>
<td>Estado</td>
<td><input type='text' name='edo' value='' /></td>
</tr>
<tr>
<td>Localidad</td>
<td><input type='text' name='loca' value='$' /></td>
</tr>
<tr>
<td colspan='2'><label>
<div align='center'>
<input type='button' value='Registrar' Onclick='validar();'/>
</div>
</label></td>
</tr>
</table>
</form>
<p>";
}
}
?>
</body>
</html>
de antemano gracias :D
Para lo que entendí quieres, lo puedes resolver fácilmente con lo siguiente:
Selects combinados con Ajax y PHP:Citar*http://www.desarrolloweb.com/articulos/selects-combinados-con-ajax-php.html
Ejemplo de uso:Citar*http://www.desarrolloweb.com/articulos/ejemplos/ajax/xajax/selects_combinados.php
Exacto... yo lo harìa con ajax e innerhtml.
Existiria otra fomar? :rolleyes:
Es decir, sin usar mas que PHP...
umm PHP+JS ..
Claro mira, entre mis codes encontre esto, cien por cien funcional, así es como lo hacia antes ... no recuerdo la fuente de origen.
<?php
$bd_host = "localhost";
$bd_usuario = "user";
$bd_password = "pass";
$bd_base = "name_db";
$con = mysql_connect($bd_host, $bd_usuario, $bd_password);
mysql_select_db($bd_base, $con);
$sql = "SELECT * from empresas";
$rs = mysql_query($sql, $con);
?>
<html>
<head>
<title>Actualizar combo sin submitear</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function componer_Centros(cod_area)
{
//alert(cod_area);
//establecemos longitud para el select depto
document.miformulario.depto.length=0;
//Asignamos un valor por defecto
document.miformulario.depto.options[0] = new Option("-- Seleccione --","","defaultSelected","");
//inicializamos el contador
var indice=1;
<?php
//ejecutamos una consulta a la tabla departamentos
$sql_depto = "SELECT * from departamentos";// where id=2";
$rs_depto = mysql_query($sql_depto, $con);
if(mysql_num_rows($rs_depto)>0)
{
while($row_depto = mysql_fetch_array($rs_depto))
{
?>
//filtramos
if(cod_area=='<?=$row_depto["idempresa"]?>')
{
document.miformulario.depto.options[indice] = new Option("<?=$row_depto["descripcion"]?>","<?=$row_depto["id"]?>");
indice = indice + 1;
}
<?php
}
}
?>
}
//________________________________________________________________
function componer_Recursos(cod_area)
{
//alert(cod_area);
//establecemos longitud para el select depto
document.miformulario.recursos.length=0;
//Asignamos un valor por defecto
document.miformulario.recursos.options[0] = new Option("-- Seleccione --","","defaultSelected","");
//inicializamos el contador
var indice=1;
<?php
//ejecutamos una consulta a la tabla departamentos
$sql_depto = "SELECT * from recursos";// where id=2";
$rs_depto = mysql_query($sql_depto, $con);
if(mysql_num_rows($rs_depto)>0)
{
while($row_depto = mysql_fetch_array($rs_depto))
{
?>
//filtramos
if(cod_area=='<?=$row_depto["iddpto"]?>')
{
document.miformulario.recursos.options[indice] = new Option("<?=$row_depto["descripcion"]?>","<?=$row_depto["id"]?>");
indice = indice + 1;
}
<?php
}
}
?>
}
<?php mysql_close($con); ?>
</script>
</head>
<body>
<p>Seleccion de un select y cambiar los valores de otro select sin tener que submitar (valido segun su uso)</p>
<form name="miformulario" method="get">
<table width="249" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Empresa</td>
<td>Departamento</td>
<td>Recursos</td>
</tr>
<tr>
<td>
<select name="empresa" id="empresa" onChange="componer_Centros(this.value)">
<option value="">--Seleccione--</option>
<?php if(mysql_num_rows($rs)>0)
{
while($row = mysql_fetch_assoc($rs))
{
?>
<option value="<?=$row["id"]?>"><?=$row["descripcion"]?></option>
<?php
}
}
?>
</select>
</td>
<td>
<select name="depto" id="depto" onChange="componer_Recursos(this.value)">
<option>--seleccione--</option>
</select>
</td>
<td>
<select name="recursos" id="recursos">
<option>--seleccione--</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
puedes encontrar más ejemplos en google, su buscas por "Select combinados con (nombre del lenguaje)".
saludos,