my code stock.com

markoast

Cargar las ciudades para un país seleccionado (jquery)
by markoast

Buenas, estoy intentando hacer un script con la herramienta jquery para una web que consiste de 2 option select; uno de ellos para seleccionar el país que el usuario quiere elegir y en el otro select se cargaran las ciudades para el país que eligió el usuario en el select anterior

Snippet options

Download: Download snippet as cargar-las-ciudades-para-un-pais-seleccionado-jquery.js.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

<!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=utf-8" />
<title>Paises</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
x= $(document);
x.ready(inicializarControles);

function inicializarControles(){
    y=$("#ciudades");     
    z=$("#paises");
    z.change(cargarCiudades);
 }

function cargarCiudades() { 
 
 y.children().remove();  
 
 if (z.val()=="UY") { 
      var aCiudades = new Array();
      aCiudades[0] = "Montevideo"; 
      aCiudades[1] = "Canelones";
      aCiudades[2] = "San Jose"; 
      for(var i=0; i< aCiudades.length; i++) {
            y.append('<option value="' + aCiudades[i] + '">' + aCiudades[i] + '</option>');
      }
 }
 
  if (z.val()=="AR") {
      var aCiudades = new Array();	  
      aCiudades[0] = "Buenos Aires"; 
      aCiudades[1] = "La Plata";
      aCiudades[2] = "Rosario";
       for(var i=0; i< aCiudades.length; i++) {
           y.append('<option value="' + aCiudades[i] + '">' + aCiudades[i] + '</option>');
      }

 }


}

</script>

</head>

<body>

<select name="paises" id="paises">
<OPTION selected></OPTION>
<OPTION VALUE="UY">Uruguay</OPTION>
<OPTION VALUE="AR">Argentina</OPTION>
<OPTION VALUE="BR">Brasil</OPTION> 
</select>
<br>
<select name="ciudades" id="ciudades">

</select>

</body>
</html>


http://foro.elhacker.net/desarrollo_web/cargar_las_ciudades_para_un_pais_seleccionado_jquery-t294363.0.html#ixzz1Q0ziGcHW

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.