Código:
<!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);
var aCiudades = new Array();
function inicializarControles(){
y=$("#ciudades");
x=$("#paises");
x.click(cargarCiudades);
}
function cargarCiudades() {
if (x.value=="UY") {
aCiudades.clear();
aCiudades[0] = "Montevideo";
aCiudades[1] = "Canelones";
aCiudades[3] = "San Jose";
for(var i=0; i< aCiudades.length; i++) {
y.append(aCiudades[i]);
}
}
if (x=="AR") {
aCiudades.clear();
aCiudades[0] = "Buenos Aires";
aCiudades[1] = "La Plata";
aCiudades[3] = "Rosario";
for(var i=0; i< aCiudades.length; i++) {
y.append(aCiudades[i]);
}
}
}
</script>
</head>
<body>
<select name="paises" id="paises">
<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>
<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);
var aCiudades = new Array();
function inicializarControles(){
y=$("#ciudades");
x=$("#paises");
x.click(cargarCiudades);
}
function cargarCiudades() {
if (x.value=="UY") {
aCiudades.clear();
aCiudades[0] = "Montevideo";
aCiudades[1] = "Canelones";
aCiudades[3] = "San Jose";
for(var i=0; i< aCiudades.length; i++) {
y.append(aCiudades[i]);
}
}
if (x=="AR") {
aCiudades.clear();
aCiudades[0] = "Buenos Aires";
aCiudades[1] = "La Plata";
aCiudades[3] = "Rosario";
for(var i=0; i< aCiudades.length; i++) {
y.append(aCiudades[i]);
}
}
}
</script>
</head>
<body>
<select name="paises" id="paises">
<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>
Jquery: http://code.jquery.com/jquery-1.4.2.js
Y bueno el problema esta en la funcion cargarCiudades() mas precisamente en el for donde recorro las ciudades cargadas en el array , intente hacer un append.. pero no tengo idea de como hacer para que aparezcan en su correspondiente select ciudades... alguna idea? thanks!