xurxinho
Código:
function selector(s,s2){
if(selected(s)){
putSelect(s2,getTextSelect(s),getValueSelect(s));
delSelect(s);
}
}
1- Olvidaste crear la funcion " selected " , por eso tu codigo da error .
2- Los enlaces estan alreves
Debe de ser haci
Código HTML:
<a href="#" onclick="selector('s1','s2');">Poner</a>
<a href="#" onclick="selector('s2','s1');">Quitar</a>
Modifique el codigo , y ahora luce de esta manera.
Código:
<script type='text/javascript'>
function selector(s,s2){
if(selected(s)){
putSelect(s2,getTextSelect(s),getValueSelect(s));
} delSelect(s);
}
function selected(s){
var sel=document.getElementById(s);
var index = sel.selectedIndex;
if(index>-1){
return true;
}else{return false;
}
}
function putSelect(id,texto,valor){
var sel=document.getElementById(id);
sel[sel.length]= new Option(texto,valor);
}
function getTextSelect(id){
var sel=document.getElementById(id);
var indiceSeleccionado = sel.selectedIndex;
return sel.options[indiceSeleccionado].text;
}
function getValueSelect(id){
var sel=document.getElementById(id);
return sel.value;
}
function delSelect(id){
var sel=document.getElementById(id);
if (sel.selectedIndex >= 0) {
sel.options[sel.selectedIndex]=null;
sel.selectedIndex=0;
}
}
</script>
Código HTML:
<div>
<select id="s1" class="opciones" size="15">
<option value="directorio">Catálogo</option>
<option value="configuracion">Configuración</option>
<option value="enlace">Enlaces</option>
<option value="rotativo">Rotativo</option>
</select>
<select id="s2" class="opciones" size="15">
<option value="album">Álbum</option>
<option value="contenidos">Contenidos</option>
<option value="disenho">Diseño</option>
<option value="ficha_empresa">Ficha de Empresa</option>
<option value="microweb">Espacios</option><option value="localizacion">Localizacion</option>
</select>
<a href="#" onclick="selector('s1','s2');">Poner</a>
<a href="#" onclick="selector('s2','s1');">Quitar</a>
</div>