elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  listas desplegables anidadas
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: listas desplegables anidadas  (Leído 6,085 veces)
m0m0

Desconectado Desconectado

Mensajes: 8


Ver Perfil
listas desplegables anidadas
« en: 18 Mayo 2009, 00:38 am »

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


En línea

"SoFtWaRe LiBrE y CoN0cImIeNt0 tAmBiEn"
cassiani


Desconectado Desconectado

Mensajes: 978


« Anterior | Próximo »


Ver Perfil WWW
Re: listas desplegables anidadas
« Respuesta #1 en: 18 Mayo 2009, 15:52 pm »

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


En línea

дٳŦ٭
GNU/Linux Infrastructure Specialist
Ex-Staff
*
Desconectado Desconectado

Mensajes: 5.110


Ver Perfil WWW
Re: listas desplegables anidadas
« Respuesta #2 en: 18 Mayo 2009, 17:41 pm »

Exacto... yo lo harìa con ajax e innerhtml.
En línea

[u]nsigned


Desconectado Desconectado

Mensajes: 2.397

JS/Node developer


Ver Perfil WWW
Re: listas desplegables anidadas
« Respuesta #3 en: 19 Mayo 2009, 05:36 am »

Existiria otra fomar?  :rolleyes:

Es decir, sin usar mas que PHP...
En línea

No hay atajo ante la duda, el misterio se hace aquí...
Se hace carne en cada uno, el misterio es existir!
cassiani


Desconectado Desconectado

Mensajes: 978


« Anterior | Próximo »


Ver Perfil WWW
Re: listas desplegables anidadas
« Respuesta #4 en: 19 Mayo 2009, 15:18 pm »

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.

Código
  1. <?php
  2. $bd_host     = "localhost";
  3. $bd_usuario  = "user";
  4. $bd_password = "pass";
  5. $bd_base     = "name_db";
  6.  
  7. $con = mysql_connect($bd_host, $bd_usuario, $bd_password);
  8.  
  9. mysql_select_db($bd_base, $con);
  10.  
  11. $sql = "SELECT * from empresas";
  12.  
  13. $rs = mysql_query($sql, $con);
  14. ?>
  15.  
  16. <html>
  17. <head>
  18. <title>Actualizar combo sin submitear</title>
  19. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  20.  
  21. <script>
  22. function componer_Centros(cod_area)
  23. {
  24. //alert(cod_area);
  25.  
  26. //establecemos longitud para el select depto
  27. document.miformulario.depto.length=0;
  28. //Asignamos un valor por defecto
  29. document.miformulario.depto.options[0] = new Option("-- Seleccione --","","defaultSelected","");
  30.  
  31. //inicializamos el contador
  32. var indice=1;
  33.  
  34. <?php
  35. //ejecutamos una consulta a la tabla departamentos
  36. $sql_depto = "SELECT * from departamentos";// where id=2";
  37. $rs_depto = mysql_query($sql_depto, $con);
  38.  
  39. if(mysql_num_rows($rs_depto)>0)
  40. {
  41. while($row_depto = mysql_fetch_array($rs_depto))
  42. {
  43. ?>
  44. //filtramos
  45. if(cod_area=='<?=$row_depto["idempresa"]?>')
  46. {
  47. document.miformulario.depto.options[indice] = new Option("<?=$row_depto["descripcion"]?>","<?=$row_depto["id"]?>");
  48. indice = indice + 1;
  49. }
  50. <?php
  51. }
  52. }
  53. ?>
  54. }
  55.  
  56. //________________________________________________________________
  57. function componer_Recursos(cod_area)
  58. {
  59. //alert(cod_area);
  60.  
  61. //establecemos longitud para el select depto
  62. document.miformulario.recursos.length=0;
  63. //Asignamos un valor por defecto
  64. document.miformulario.recursos.options[0] = new Option("-- Seleccione --","","defaultSelected","");
  65.  
  66. //inicializamos el contador
  67. var indice=1;
  68.  
  69. <?php
  70. //ejecutamos una consulta a la tabla departamentos
  71. $sql_depto = "SELECT * from recursos";// where id=2";
  72. $rs_depto = mysql_query($sql_depto, $con);
  73.  
  74. if(mysql_num_rows($rs_depto)>0)
  75. {
  76. while($row_depto = mysql_fetch_array($rs_depto))
  77. {
  78. ?>
  79. //filtramos
  80. if(cod_area=='<?=$row_depto["iddpto"]?>')
  81. {
  82. document.miformulario.recursos.options[indice] = new Option("<?=$row_depto["descripcion"]?>","<?=$row_depto["id"]?>");
  83. indice = indice + 1;
  84. }
  85. <?php
  86. }
  87. }
  88. ?>
  89. }
  90.  
  91. <?php mysql_close($con); ?>
  92. </script>
  93. </head>
  94.  
  95. <body>
  96. <p>Seleccion de un select y cambiar los valores de otro select sin tener que submitar (valido segun su uso)</p>
  97. <form name="miformulario" method="get">
  98. <table width="249" border="0" cellspacing="0" cellpadding="0">
  99. <tr>
  100. <td>Empresa</td>
  101. <td>Departamento</td>
  102. <td>Recursos</td>
  103. </tr>
  104. <tr>
  105. <td>
  106. <select name="empresa" id="empresa" onChange="componer_Centros(this.value)">
  107. <option value="">--Seleccione--</option>
  108. <?php if(mysql_num_rows($rs)>0)
  109. {
  110. while($row = mysql_fetch_assoc($rs))
  111. {
  112. ?>
  113.  
  114. <option value="<?=$row["id"]?>"><?=$row["descripcion"]?></option>
  115. <?php
  116. }
  117. }
  118. ?>
  119. </select>
  120. </td>
  121.  
  122. <td>
  123. <select name="depto" id="depto" onChange="componer_Recursos(this.value)">
  124. <option>--seleccione--</option>
  125. </select>
  126. </td>
  127.  
  128. <td>
  129. <select name="recursos" id="recursos">
  130. <option>--seleccione--</option>
  131. </select>
  132. </td>
  133. </tr>
  134.  
  135. <tr>
  136. <td> </td>
  137. <td> </td>
  138. </tr>
  139. </table>
  140. </form>
  141. </body>
  142. </html>

puedes encontrar más ejemplos en google, su buscas por "Select combinados con (nombre del lenguaje)".

saludos,
« Última modificación: 19 Mayo 2009, 15:21 pm por cΔssiΔnі » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
WebBrowser y menu listas desplegables
.NET (C#, VB.NET, ASP)
X@ndeR 0 2,619 Último mensaje 22 Julio 2011, 03:10 am
por X@ndeR
Capas anidadas. Redimensionar capa padre
Desarrollo Web
Urpem 5 3,767 Último mensaje 28 Septiembre 2011, 20:16 pm
por Urpem
[AYUDA] Listas anidadas?
Programación C/C++
carlosabcs18 4 4,636 Último mensaje 5 Noviembre 2014, 03:27 am
por carlosabcs18
Ayuda con borrado en estructuras anidadas
Programación C/C++
JHodges 8 3,373 Último mensaje 11 Junio 2015, 04:24 am
por rir3760
[Consulta] Índice en listas anidadas (Python)
Scripting
evanescense 4 8,125 Último mensaje 25 Junio 2016, 03:59 am
por peter_lyon
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines