Trier une liste à choix multiples liées par des labels

Contenu du snippet

Trier une liste de contacts en fonction de leur poste de travail !

Je suis en train de me creser la tête pour liéer 3 ListBox à choix multiple.

Fabiano13

Source / Exemple :


<HTML>
<HEAD>
<TITLE></TITLE>
<script type="text/javascript">
            
function Supprimer(_id, _type,_ids){
    var ctrl = document.getElementById(_id);
    if ( ctrl.listChilds == null){
            ctrl.listChilds = new Array();
            var ctrlsChilds = ctrl.getElementsByTagName("OPTGROUP");
            for ( var i = 0; i < ctrlsChilds.length; i++){
                    var clone = ctrlsChilds[i].cloneNode(true);
                    clone._id = clone.id;
                    clone.id =null;
                    var childs = clone.getElementsByTagName ("OPTION");
                    for ( var j = 0;  j< childs.length; j++){
                            childs[j]._id = childs[j].id;
                            childs[j].id = null;
                    }
                    ctrl.listChilds.push (clone );
            }
    }
    var typeObj = ctrl.getElementsByTagName (_type);
    for ( var i =0 ; i < _ids.length; i++){
        for ( var j = 0; j < typeObj.length; j++){
            if ( typeObj[j].label == _ids[i] ){
                    typeObj[j].parentNode.removeChild ( typeObj[j] );
                    j--
            }
        }
    }
}

function Reconstruire(_id){
    var ctrl = document.getElementById(_id);
    // réinitialise le composant.
    ctrl.innerHTML = "";
    // ajoute tous ces fils
   
    for ( var i = 0; i < ctrl.listChilds.length; i++){
             var ret = ctrl.appendChild ( ctrl.listChilds[i]) ;
            // réattribut l'id
            ret.id = ret._id;
            // fais de même pour ces fils
            for ( var j = 0; j < ret.childNodes.length; j++){
                if ( ret.childNodes[j]._id != null )
                    ret.childNodes[j].id = ret.childNodes[j]._id;
            }
    }
    ctrl.listChilds = null;
}

function Trier(){
var selectione=""; 
for (i=0; i<document.getElementById('sFonction').options.length; i++) { 
if (!document.getElementById('sFonction').options[i].selected ) { 
      selectione += "'" + document.getElementById('sFonction').options[i].label + "',";  }
}
var sSelection = selectione.substr(0,selectione.length - 1)
var ctrl = document.getElementById('sContact');
if ( ctrl.listChilds != null){
Reconstruire('sContact')}
Supprimer('sContact','OPTION',eval("[" + sSelection + "]"))
}
</script>
</HEAD>
<BODY>
<select onchange="Trier();" size=47 id="sFonction" multiple>
    <optgroup id="Direction" label="Direction" style="background-color:#FFFFAA">
        <option label="label_1_" style="background-color:#FFFFAA">Président Directeur Général</option>
        <option label="label_2_" style="background-color:#FFFFAA">Directeur Général</option>
    </optgroup>
    <optgroup   id="Marketing" label="Marketing" style="background-color:#AAFFFF">
        <option label="label_3_" style="background-color:#AAFFFF">Directeur Marketing</option>
        <option label="label_4_" style="background-color:#AAFFFF">Chef Produit</option>
        <option label="label_5_" style="background-color:#AAFFFF">Assitant Marketing</option>
        <option label="label_6_" style="background-color:#AAFFFF">Responsable Licence</option>
    </optgroup>
    <optgroup   id="PAO" label="PAO" style="background-color:#FFAAFF">
        <option label="label_7_" style="background-color:#FFAAFF">Directeur de Création</option>
        <option label="label_8_" style="background-color:#FFAAFF">Directeur Artistique</option>
        <option label="label_9_" style="background-color:#FFAAFF">Graphiste</option>
    </optgroup>
</select>

<select size=47 id="sContact" multiple>
    <optgroup   id="Client" label="Client" style="background-color:#D7EBFF">
        <option label="label_3_" id="id_1_" style="background-color:#D7EBFF">Guillermo Alcaide (Directeur Marketing)</option>
        <option label="label_4_" id="id_2_" style="background-color:#D7EBFF">Thomas Leleu (Chef Produit)</option>
        <option label="label_2_" id="id_3_" style="background-color:#D7EBFF">Alexandre Penaud (Directeur Général)</option>
        <option label="label_1_" id="id_4_" style="background-color:#D7EBFF">Julien Obry (Président Directeur Général)</option>
        <option label="label_5_" id="id_5_" style="background-color:#D7EBFF">Nathan Martinet (Assitant Marketing)</option>
        <option label="label_3_" id="id_6_" style="background-color:#D7EBFF">Laurent Bram (Directeur Marketing)</option>
        <option label="label_6_" id="id_7_" style="background-color:#D7EBFF">Vincent Boginoff (Responsable Licence)</option>
        <option label="label_1_" id="id_8_" style="background-color:#D7EBFF">Mathieu Guenat (Président Directeur Général)</option>
        <option label="label_8_" id="id_9_" style="background-color:#D7EBFF">Jonathan Dahan (Directeur Artistique)</option>
        <option label="label_2_" id="id_10_" style="background-color:#D7EBFF">Christophe Lenzi (Directeur Général)</option>
        <option label="label_1_" id="id_11_" style="background-color:#D7EBFF">Adrien Gombocz (Président Directeur Général)</option>
        <option label="label_9_" id="id_12_" style="background-color:#D7EBFF">Romain Sichez (Graphiste)</option>
        <option label="label_5_" id="id_13_" style="background-color:#D7EBFF">Nicolas Tholozan (Assitant Marketing)</option>
    </optgroup>
    <optgroup   id="Utilisateur" label="Utilisateur" style="background-color:#DED8E9">
        <option label="label_3_" id="id_14_" style="background-color:#DED8E9">Antoine Hamard (Directeur Marketing)</option>
        <option label="label_2_" id="id_15_" style="background-color:#DED8E9">Alexis Klegou (Directeur Général)</option>
        <option label="label_7_" id="id_16_" style="background-color:#DED8E9">Vincent Dubosclard (Directeur de Création)</option>
        <option label="label_1_" id="id_17_" style="background-color:#DED8E9">Luca Rovetta (Président Directeur Général)</option>
        <option label="label_8_" id="id_18_" style="background-color:#DED8E9">Robert Khoury (Directeur Artistique)</option>
        <option label="label_4_" id="id_19_" style="background-color:#DED8E9">Arthur Surreaux (Chef Produit)</option>
        <option label="label_6_" id="id_20_" style="background-color:#DED8E9">Hakim Rezgui (Responsable Licence)</option>
        <option label="label_3_" id="id_21_" style="background-color:#DED8E9">Laurent Bondaz (Directeur Marketing)</option>
       <option label="label_3_" id="id_22_" style="background-color:#DED8E9">Thomas van Cauter (Directeur Marketing)</option>
        <option label="label_9_" id="id_23_" style="background-color:#DED8E9">Boris Obama (Graphiste)</option>
        <option label="label_7_" id="id_24_" style="background-color:#DED8E9">Yannick Thomet (Directeur de Création)</option>
        <option label="label_1_" id="id_25_" style="background-color:#DED8E9">Benoit Bottero (Président Directeur Général)</option>
        <option label="label_5_" id="id_26_" style="background-color:#DED8E9">Benjamin Cselenko (Assitant Marketing)</option>
        <option label="label_1_" id="id_27_" style="background-color:#DED8E9">Hugo Vouillat (Président Directeur Général)</option>
        <option label="label_6_" id="id_28_" style="background-color:#DED8E9">Kristof de Leeuw (Responsable Licence)</option>
        <option label="label_4_" id="id_29_" style="background-color:#DED8E9">Mark de Jong (Chef Produit)</option>
        <option label="label_2_" id="id_30_" style="background-color:#DED8E9">Sliman Taghzouit (Directeur Général)</option>
        <option label="label_9_" id="id_31_" style="background-color:#DED8E9">Boris Oumow (Graphiste)</option>
        <option label="label_7_" id="id_32_" style="background-color:#DED8E9">Teddy Ranghella (Directeur de Création)</option>
    </optgroup>
    <optgroup  id="Visiteur" label="Visiteur" style="background-color:#FFD393">
        <option label="label_5_" id="id_33_" style="background-color:#FFD393">Konstantinos Kalaitzis (Assitant Marketing)</option>
        <option label="label_2_" id="id_34_" style="background-color:#FFD393">Yannick Thivant (Directeur Général)</option>
        <option label="label_1_" id="id_35_" style="background-color:#FFD393">Bilo Katis (Président Directeur Général)</option>
        <option label="label_7_" id="id_36_" style="background-color:#FFD393">Benoit Viant(Directeur de Création)</option>
        <option label="label_3_" id="id_37_" style="background-color:#FFD393">Gérôme Landin (Directeur Marketing)</option>
        <option label="label_2_" id="id_38_" style="background-color:#FFD393">Didier Ouzer (Directeur Général)</option>
        <option label="label_6_" id="id_39_" style="background-color:#FFD393">Armando Gijon (Responsable Licence)</option>
        <option label="label_2_" id="id_40_" style="background-color:#FFD393">Daniel Cousin (Directeur Général)</option>
    </optgroup>
</select></BODY></HTML>

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.