Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/03/2013, 05:38
DoHITB
 
Fecha de Ingreso: abril-2012
Ubicación: 41°37′00″N, 00°37′00″E
Mensajes: 462
Antigüedad: 12 años, 11 meses
Puntos: 33
Select se vacía

Hola

Llevo toda la mañana ofuscado con un problema al que no le veo el fallo... a ver si me ayudáis, por favor.

Tengo dos selects:

Código PHP:
Ver original
  1. <select name="country" id="country" onmouseover="loadCountry(this);" onchange="manageCountry(this);"></select>
  2. <select name="city" id="city"></select>

Y estas dos funciones:

Código Javascript:
Ver original
  1. function loadCountry(e){
  2.     k='country';
  3.    
  4.     if(e.options.length>0){
  5.         return false;
  6.     }
  7.    
  8.     getEv('country', 'c=');//llamada AJAX con "eval()". El retorno es:
  9.  
  10. /*
  11. retorno:
  12. G_country=[value|code, ...]
  13. */
  14.  
  15.  
  16.     for(i=0;i<G_country.length;i++){//ge es una función que retorna el elemento con ese id
  17.         gc = G_country[i].split('|');
  18.         opt = document.createElement("OPTION");
  19.         opt.innerText = gc[1];
  20.         opt.value = gc[0];
  21.         ge(k).add(opt, 0);
  22.     }
  23. }
  24.  
  25. function manageCountry(e){
  26.     getEv('country', 'c='+e.options[e.selectedIndex].value);
  27.     k='city';
  28.     for(i=0;i<G_country.length;i++){
  29.         gc = G_country[i].split('|');
  30.         opt = document.createElement("OPTION");
  31.         opt.innerText = gc[1];
  32.         opt.value = gc[0];
  33.         ge(k).add(opt, 0);
  34.     }
  35. }

El "onmouseover" funciona bien. Pero cuando selecciono algo en "country", me carga la lista de city (manageCountry, bien), pero la opción de "country" se me cambia al primer valor... y no entiendo porqué.

¿No se supone que al tener varias opciones, haría un return y detendría la función loadCountry?

Gracias por la ayuda.