Ver Mensaje Individual
  #4 (permalink)  
Antiguo 05/02/2009, 15:35
Avatar de PIRRUMAN
PIRRUMAN
 
Fecha de Ingreso: febrero-2006
Ubicación: Monterrey, Nuevo León
Mensajes: 633
Antigüedad: 19 años
Puntos: 53
Respuesta: Javascript mover opciones entre listas

saludos de nuevo,,

aaaa mira lo q pasa es q nulificas el valor inicial ("-")

if (obj2.options[0].value=='-')
obj2.options[0]=null;

quitale esas dos lineas a las dos pruebas y saldra ya lo cheque ;)
entonces tu codigo quedaria asi :

<html><head>
<script type="text/javascript">
function pasar1() {
obj1=document.getElementById('lista1');
if (obj1.selectedIndex==-1) return;

for (i=0; opt=obj1.options[i]; i++)
if (opt.selected) {
valor=opt.value; // almacenar value
txt=obj1.options[i].text; // almacenar el texto
obj1.options[i]=null; // borrar el item seleccionado
obj2=document.getElementById('lista2');

//if (obj2.options[0].value=='-')<<<<<<estan en comentario
//obj2.options[0]=null;<<<<<<<<<<<< " " "

opc = new Option(txt,valor);
eval(obj2.options[obj2.options.length]=opc);
}
}
function pasar2() {
obj1=document.getElementById('lista2');
if (obj1.selectedIndex==-1) return;

for (i=0; opt=obj1.options[i]; i++)
if (opt.selected) {
valor=opt.value; // almacenar value
txt=obj1.options[i].text; // almacenar el texto
obj1.options[i]=null; // borrar el item seleccionado
obj2=document.getElementById('lista1');
//if (obj2.options[0].value=='-')<<<<<<estan en comentario
//obj2.options[0]=null;<<<<<<<<<<<< " " "
opc = new Option(txt,valor);
eval(obj2.options[obj2.options.length]=opc);
}
}
</script></head><body><center>
<select id="lista1" size="6" multiple="multiple" onclick="pasar1()">
<option name=1 id=1 value="a">a</option>
<option name=2 id=2 value="b">b</option>
<option name=3 id=3 value="c">c</option>
<option name=4 id=4 value="d">d</option>
<option name=5 id=5 value="e">e</option>
<option name=6 id=6 value="g">g</option>
</select>
<select id="lista2" size="6" multiple="multiple" onclick="pasar2()">
////no hay necesidad del option
</select>
</body></html>

CUIDESE SUERTE
__________________
“Prefiero ser un tonto momentaneo que un eterno ignorante”
“¡El éxito es resultado de los aciertos,los aciertos resultado de la experiencia y la experiencia resultado de los errores!”