Select order

Discussion in 'JavaScript' started by FlashO, Apr 22, 2008.

  1. #1
    I have a select multiple. The list1 contains elements of a table of my database.
    When I double click on various elements of the list1, move this elements to the list2 of select. The problem comes when you want to remove any elements of the list2 because I can double click in the element and returned to list1, but in the end of the list1 and not to your site. Her site is alphabetically ordered.
    Can You help me?

    
    
    function anadir() { 
        obj=document.getElementById('lista'); 
        if (obj.selectedIndex==-1) return; 
        valor=obj.value; 
        txt=obj.options[obj.selectedIndex].text; 
        obj.options[obj.selectedIndex]=null; 
        obj2=document.getElementById('seleccionados'); 
        opc = new Option(txt,valor); 
        eval(obj2.options[obj2.options.length]=opc);  
    } 
    	
    function eliminar() { 
        obj=document.getElementById('seleccionados'); 
        if (obj.selectedIndex==-1) return; 
        valor=obj.value; 
        txt=obj.options[obj.selectedIndex].text; 
        obj.options[obj.selectedIndex]=null; 
        obj2=document.getElementById('lista'); 
        opc = new Option(txt,valor); 
        eval(obj2.options[obj2.options.length]=opc);     
    } 
    	
    	function anadirTodos(val) {
    		var newOpt
    		for (k=0;k<val.lista.length;k++) {
    			newOpt = document.createElement("OPTION");
    			newOpt.text = val.lista.options[k].text;
    			newOpt.value = val.lista.options[k].value;
    			val.seleccionados.options.add(newOpt,val.seleccionados.length);
    			//val.lista.options.remove(k);
    		}
    		
    		for (k=0;k<val.lista.length;) {
    			val.lista.options.remove(k);
    		}
    		
    
    	}
    	
    	function eliminarTodos(val) {
    		var newOpt
    		for (k=0;k<val.seleccionados.length;k++) {
    			newOpt = document.createElement("OPTION");
    			newOpt.text = val.seleccionados.options[k].text;
    			newOpt.value = val.seleccionados.options[k].value;
    			val.lista.options.add(newOpt,val.lista.length);
    			//val.lista.options.remove(k);
    		}
    		
    		for (k=0;k<val.seleccionados.length;) {
    			val.seleccionados.options.remove(k);
    		}
    	}
    	
    </script>
    
    Code (markup):

     
    FlashO, Apr 22, 2008 IP