Le code :
Entre <HEAD> et </HEAD> :
- Code: Tout sélectionner
<SCRIPT language="JavaScript">
//initialise une liste
function ini(form,list1,list2){
var MaTb = new Array("Jeff","Elene","Pierrot","Camille","Yves","Jul","Kabil");
list1.options.length=0;
list2.options.length=0;
MaTb.sort();
var i
for (i=0; i<6; i++) {
var o=new Option(MaTb[i],MaTb[i]);
list1.options[list1.options.length]=o;
}
}
//passe les données de la liste 1 à la liste 2 et les trie par ordre alphabétique
function gtod(form,list1,list2){
for(yo=0;yo<list1.length;yo++){
if(list1.options[yo].selected == true){
var p= new Option(list1.options[yo].value,list1.options[yo].value);
list2.options[list2.options.length]=p;
list1.options[yo] = null;
yo=yo-1;
}
}
//trie de la liste, on creer un tab, on le trie et on reconstruit la liste
var tbl = new Array()
for(i=0;i<list2.length;i++){
tbl.push(list2.options[i].value);
}
tbl.sort();//trie le tableau
list2.options.length=0;//efface la liste 2
for(i=0;i<tbl.length;i++){ //rempli la liste avec les données trié
var p= new Option(tbl[i],tbl[i]);
list2.options[list2.options.length]=p;
}
}
</SCRIPT>
Entre <BODY> et </BODY> :
- Code: Tout sélectionner
initialiser la liste de gauche :
<input type="button" name="init" value="Initialisation" onclick="ini(this.form,this.form.pers1,this.form.pers2);"><br />
<br />
<select name="pers1" align="top" size="6" multiple="multiple">
<option value="Liste vide">Liste vide...
</select>
<input type="button" name="boutvG" value="<" onclick="gtod(this.form,this.form.pers2,this.form.pers1);">
<input type="button" name="boutvD" value=">" onclick="gtod(this.form,this.form.pers1,this.form.pers2);">
<select name="pers2" align="top" size="6" multiple="multiple">
<option value="Liste vide">Liste vide...
</select>
</form>
