vipersuelo Posted February 15, 2011 Report Share Posted February 15, 2011 QUE TAL AMIGOS ....BUENO TENGO UN CODIGO DONDE IMPLEMENTO UN SELECT DEPENDIENTE....EL PROBLEMA ES QUE CUANDO SELECCIONO EN EL PRIMER SELECT...QUE HACE REFERENCIA A PAISES....ME CARGA EN EL SEGUNDO LAS RESPECTIVAS CIUDADES DE ACUERDO AL PAIS SELECCIONADO DE FORMA CORRECTA...EL PROBLEMA ES QUE EL PRIMER SELECT SE REFRESCA Y VUELVE A TENER EL CAMPO EN BLANCO.... AKA LES DEJO EL CODIGO <?php mysql_connect("localhost","root")or die ('Ha fallado la conexión: '.mysql_error()); mysql_select_db("pais")or die ('Ha fallado la conexión: '.mysql_error()); $re=mysql_query("select * from pais"); //el @ sirve para que no salga ese mensaje de NOTICE al momento de ejecutar por 1ra ve nuestro codigo. if(isset($_POST["pais"])){ $pais=$_POST["pais"]; $re1=mysql_query("select * from ciudad where cod_pais=".$pais.""); $re2=mysql_query("select nombre from pais where cod_pais=".$pais.""); $j[]=mysql_fetch_array($re2); }else{ @$j[nombre]="seleccione pais"; } ?> <form id="form1" name="form1" method="post" action=""> Nombre completo <input name="nombre" type="text" id="nombre" value="<?php echo @$_POST[nombre]?>" /> <br> <br> Pais: <select name="pais" size="1" id="pais" onchange="form1.submit()" style="width:200px"> <option value="" > Seleccione Pais</option> <?php while($f=mysql_fetch_array($re)){ echo"<option value=".$f[cod_pais].">".$f[nombre]."</option>"; } ?> </select> <br /> Ciudad: <select name="ciudad" size="1" id="ciudad" style="width:200px"> <?php while($f1=mysql_fetch_array($re1)){ echo"<option>".$f1[nombre]."</option>"; } ?> </select> </p> </form> Link to comment Share on other sites More sharing options...
nazhox Posted February 15, 2011 Report Share Posted February 15, 2011 (edited) intenta con esto while($f=mysql_fetch_array($re)){ $sel = ($f[cod_pais]==$pais) ? "SELECTED" : ""; echo"<option value='".$f[cod_pais]."' ".$sel.">".$f[nombre]."</option>"; } sustituye ese "while" por el que carga el selec pais Edited February 15, 2011 by nazhox Link to comment Share on other sites More sharing options...
vipersuelo Posted February 15, 2011 Author Report Share Posted February 15, 2011 oooo viejo.....te pasaste ...funciona perfect...... que bueno que alla gente que te ayude y comparta sus conocimientos... tuve pegao como 3 dias con este asunto... mil gracias...... Link to comment Share on other sites More sharing options...
nazhox Posted February 15, 2011 Report Share Posted February 15, 2011 de nada :D Link to comment Share on other sites More sharing options...
vipersuelo Posted February 15, 2011 Author Report Share Posted February 15, 2011 nazho.......probando el script... y modificandolo...... este no me funka..... te explico......si en el formulario agrego en el action una pagina ke registre los datos colocados en los select........ al seleccionar el primer select....me envia de inmediato a la pagina del action...... el problema creo ke esta en el onchange=form1.submit(); ahy va el codigo <?php mysql_connect("localhost","root")or die ('Ha fallado la conexión: '.mysql_error()); mysql_select_db("bdeinlab")or die ('Ha fallado la conexión: '.mysql_error()); $re=mysql_query("select * from pais"); //el @ sirve para que no salga ese mensaje de NOTICE al momento de ejecutar por 1ra ve nuestro codigo. if(isset($_POST["pais"])){ $pais=$_POST["pais"]; $re1=mysql_query("select * from ciudad where cod_pais=".$pais.""); $re2=mysql_query("select nombre from pais where cod_pais=".$pais.""); //$j[]=mysql_fetch_array($re2); }else{ @$j[nombre]="seleccione pais"; } ?> <form id="form1" name="form1" method="post" action="cliente.php"> Pais: <select name="pais" size="1" id="pais" onchange="form1.submit()" style="width:200px"> <option value="" > Seleccione Pais</option> <?php while($f=mysql_fetch_array($re)){ $sel = ($f[cod_pais]==$pais) ? "SELECTED" : ""; echo"<option value='".$f[cod_pais]."' ".$sel.">".$f[nombre]."</option>"; } ?> </select> <br /> Ciudad: <select name="ciudad" size="1" id="ciudad" style="width:200px"> <?php while($f1=mysql_fetch_array($re1)){ echo"<option>".$f1[nombre]."</option>"; } ?> </select> </p> </form> sin no colo nada en el action...funciona bien....pero necesito colocar una pagina ahy, para keme registre estos datos en la BD Link to comment Share on other sites More sharing options...
rkstro Posted February 15, 2011 Report Share Posted February 15, 2011 (edited) Echale una mirada a: http://www.recursosdelweb.com/combos-depen...ery-javascript/ Aqui hay otra: http://www.miguelmanchego.com/2009/combos-...es-ajax-jquery/ Tal vez asi te funciona Edited February 15, 2011 by r_kstro Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now