Trier une liste liée par 2 autres liste à choix multiples.
PS : je remercie Zobibol et PetoleTeam qui sans eux je ne serai pas arriver à ce résultat !
Fabiano13
Source / Exemple :
<HTML>
<HEAD>
<TITLE></TITLE>
<script type="text/javascript">
function Supprimer(_id, _type,_ids_1,_ids_2){
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);
var Lnids_1 = document.getElementById('sFonction').options.length
var Lnids_2 = document.getElementById('sSecteur').options.length
if((_ids_1.length==Lnids_1)||(_ids_1.length==0)){_ids_1="y".split(",");}
if((_ids_2.length==Lnids_2)||(_ids_2.length==0)){_ids_2="x".split(",");}
for ( var i =0 ; i < _ids_1.length; i++){
for ( var k = 0; k < _ids_2.length; k++){
for ( var j = 0; j < typeObj.length; j++){
if ((_ids_1[0]!="y")&&(_ids_2[0]!="x")){
if ( (typeObj[j].label_1 == _ids_1[i])||(typeObj[j].label_2 == _ids_2[k]) ){typeObj[j].parentNode.removeChild ( typeObj[j] );j--;}
}else if (_ids_1[0]=="y"){
if ( typeObj[j].label_2 == _ids_2[k] ){typeObj[j].parentNode.removeChild ( typeObj[j] );j--;}
}else if (_ids_2[0]=="x"){
if ( typeObj[j].label_1 == _ids_1[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_1="";
for (i=0; i<document.getElementById('sFonction').options.length; i++) {
if (!document.getElementById('sFonction').options[i].selected ) {
selectione_1 += "'" + document.getElementById('sFonction').options[i].label_1 + "',"; }
}
var selectione_2="";
for (i=0; i<document.getElementById('sSecteur').options.length; i++) {
if (!document.getElementById('sSecteur').options[i].selected ) {
selectione_2 += "'" + document.getElementById('sSecteur').options[i].label_2 + "',"; }
}
var sSelection_1 = selectione_1.substr(0,selectione_1.length - 1)
var sSelection_2 = selectione_2.substr(0,selectione_2.length - 1)
var ctrl = document.getElementById('sContact');
if ( ctrl.listChilds != null){Reconstruire('sContact')}
Supprimer('sContact','OPTION',eval("[" + sSelection_1 + "]"),eval("[" + sSelection_2 + "]"))
}
</script>
</HEAD>
<BODY>
<b>Fonction
Secteur d'activité
Contacts</b><br>
<select onchange="Trier();" size=47 id="sFonction" multiple>
<optgroup id="Direction" label="Direction" style="background-color:#FFFFAA">
<option label_1="label_1_" style="background-color:#FFFFAA">Président Directeur Général</option>
<option label_1="label_2_" style="background-color:#FFFFAA">Directeur Général</option>
</optgroup>
<optgroup id="Marketing" label="Marketing" style="background-color:#AAFFFF">
<option label_1="label_3_" style="background-color:#AAFFFF">Directeur Marketing</option>
<option label_1="label_4_" style="background-color:#AAFFFF">Chef Produit</option>
<option label_1="label_5_" style="background-color:#AAFFFF">Assitant Marketing</option>
<option label_1="label_6_" style="background-color:#AAFFFF">Responsable Licence</option>
</optgroup>
<optgroup id="PAO" label="PAO" style="background-color:#FFAAFF">
<option label_1="label_7_" style="background-color:#FFAAFF">Directeur de Création</option>
<option label_1="label_8_" style="background-color:#FFAAFF">Directeur Artistique</option>
<option label_1="label_9_" style="background-color:#FFAAFF">Graphiste</option>
</optgroup>
</select>
<select onchange="Trier();" size=47 id="sSecteur" multiple>
<optgroup id="Agro-Alimentaire" label="Agro-Alimentaire" style="background-color:#FF8A8A">
<option label_2="label_1_" style="background-color:#FF8A8A">Boisson</option>
<option label_2="label_2_" style="background-color:#FF8A8A">Biscuiterie</option>
</optgroup>
<optgroup id="Service" label="Service" style="background-color:#CAFF95">
<option label_2="label_3_" style="background-color:#CAFF95">Agence Communication</option>
<option label_2="label_4_" style="background-color:#CAFF95">Agence Conseil</option>
<option label_2="label_5_" style="background-color:#CAFF95">Agence Promotion</option>
<option label_2="label_6_" style="background-color:#CAFF95">Agence Créative</option>
</optgroup>
<optgroup id="Industrie" label="Industrie" style="background-color:#A8CBFF">
<option label_2="label_7_" style="background-color:#A8CBFF">Chimique</option>
<option label_2="label_8_" style="background-color:#A8CBFF">Pétrol</option>
<option label_2="label_9_" style="background-color:#A8CBFF">Papéterie</option>
</optgroup>
</select>
<select size=47 id="sContact" multiple>
<optgroup id="Client" label="Client" style="background-color:#D7EBFF">
<option label_1="label_3_" label_2="label_1_" id="id_1_" style="background-color:#D7EBFF">Guillermo Alcaide (Directeur Marketing - Boisson)</option>
<option label_1="label_4_" label_2="label_3_" id="id_2_" style="background-color:#D7EBFF">Thomas Leleu (Chef Produit - Agence Communication)</option>
<option label_1="label_2_" label_2="label_6_" id="id_3_" style="background-color:#D7EBFF">Alexandre Penaud (Directeur Général - Agence Créative)</option>
<option label_1="label_1_" label_2="label_3_" id="id_4_" style="background-color:#D7EBFF">Julien Obry (Président Directeur Général - Agence Communication)</option>
<option label_1="label_5_" label_2="label_8_" id="id_5_" style="background-color:#D7EBFF">Nathan Martinet (Assitant Marketing - Pétrol)</option>
<option label_1="label_3_" label_2="label_3_" id="id_6_" style="background-color:#D7EBFF">Laurent Bram (Directeur Marketing - Agence Communication)</option>
<option label_1="label_6_" label_2="label_5_" id="id_7_" style="background-color:#D7EBFF">Vincent Boginoff (Responsable Licence - Agence Promotion)</option>
<option label_1="label_1_" label_2="label_2_" id="id_8_" style="background-color:#D7EBFF">Mathieu Guenat (Président Directeur Général - Biscuiterie)</option>
<option label_1="label_8_" label_2="label_4_" id="id_9_" style="background-color:#D7EBFF">Jonathan Dahan (Directeur Artistique - Agence Conseil)</option>
<option label_1="label_2_" label_2="label_6_" id="id_10_" style="background-color:#D7EBFF">Christophe Lenzi (Directeur Général - Agence Créative)</option>
<option label_1="label_1_" label_2="label_5_" id="id_11_" style="background-color:#D7EBFF">Adrien Gombocz (Président Directeur Général - Agence Promotion)</option>
<option label_1="label_9_" label_2="label_1_" id="id_12_" style="background-color:#D7EBFF">Romain Sichez (Graphiste - Boisson)</option>
<option label_1="label_5_" label_2="label_2_" id="id_13_" style="background-color:#D7EBFF">Nicolas Tholozan (Assitant Marketing - Biscuiterie)</option>
</optgroup>
<optgroup id="Utilisateur" label="Utilisateur" style="background-color:#DED8E9">
<option label_1="label_3_" label_2="label_4_" id="id_14_" style="background-color:#DED8E9">Antoine Hamard (Directeur Marketing - Agence Conseil)</option>
<option label_1="label_2_" label_2="label_3_" id="id_15_" style="background-color:#DED8E9">Alexis Klegou (Directeur Général - Agence Communication)</option>
<option label_1="label_7_" label_2="label_7_" id="id_16_" style="background-color:#DED8E9">Vincent Dubosclard (Directeur de Création - Chimique)</option>
<option label_1="label_1_" label_2="label_1_" id="id_17_" style="background-color:#DED8E9">Luca Rovetta (Président Directeur Général - Boisson)</option>
<option label_1="label_8_" label_2="label_2_" id="id_18_" style="background-color:#DED8E9">Robert Khoury (Directeur Artistique - Biscuiterie)</option>
<option label_1="label_4_" label_2="label_6_" id="id_19_" style="background-color:#DED8E9">Arthur Surreaux (Chef Produit - Agence Créative)</option>
<option label_1="label_6_" label_2="label_1_" id="id_20_" style="background-color:#DED8E9">Hakim Rezgui (Responsable Licence - Boisson)</option>
<option label_1="label_3_" label_2="label_5_" id="id_21_" style="background-color:#DED8E9">Laurent Bondaz (Directeur Marketing - Agence Promotion)</option>
<option label_1="label_3_" label_2="label_2_" id="id_22_" style="background-color:#DED8E9">Thomas van Cauter (Directeur Marketing - Biscuiterie)</option>
<option label_1="label_9_" label_2="label_1_" id="id_23_" style="background-color:#DED8E9">Boris Obama (Graphiste - Boisson)</option>
<option label_1="label_7_" label_2="label_8_" id="id_24_" style="background-color:#DED8E9">Yannick Thomet (Directeur de Création - Pétrol)</option>
<option label_1="label_1_" label_2="label_9_" id="id_25_" style="background-color:#DED8E9">Benoit Bottero (Président Directeur Général - Papéterie)</option>
<option label_1="label_5_" label_2="label_9_" id="id_26_" style="background-color:#DED8E9">Benjamin Cselenko (Assitant Marketing - Papéterie)</option>
<option label_1="label_1_" label_2="label_4_" id="id_27_" style="background-color:#DED8E9">Hugo Vouillat (Président Directeur Général - Agence Conseil)</option>
<option label_1="label_6_" label_2="label_3_" id="id_28_" style="background-color:#DED8E9">Kristof de Leeuw (Responsable Licence - Agence Communication)</option>
<option label_1="label_4_" label_2="label_8_" id="id_29_" style="background-color:#DED8E9">Mark de Jong (Chef Produit - Pétrol)</option>
<option label_1="label_2_" label_2="label_5_" id="id_30_" style="background-color:#DED8E9">Sliman Taghzouit (Directeur Général - Agence Promotion)</option>
<option label_1="label_9_" label_2="label_7_" id="id_31_" style="background-color:#DED8E9">Boris Oumow (Graphiste - Chimique)</option>
<option label_1="label_7_" label_2="label_1_" id="id_32_" style="background-color:#DED8E9">Teddy Ranghella (Directeur de Création - Boisson)</option>
</optgroup>
<optgroup id="Visiteur" label="Visiteur" style="background-color:#FFD393">
<option label_1="label_5_" label_2="label_9_" id="id_33_" style="background-color:#FFD393">Konstantinos Kalaitzis (Assitant Marketing - Papéterie)</option>
<option label_1="label_2_" label_2="label_8_" id="id_34_" style="background-color:#FFD393">Yannick Thivant (Directeur Général - Pétrol)</option>
<option label_1="label_1_" label_2="label_6_" id="id_35_" style="background-color:#FFD393">Bilo Katis (Président Directeur Général - Agence Créative)</option>
<option label_1="label_7_" label_2="label_3_" id="id_36_" style="background-color:#FFD393">Benoit Viant(Directeur de Création - Agence Communication)</option>
<option label_1="label_3_" label_2="label_6_" id="id_37_" style="background-color:#FFD393">Gérôme Landin (Directeur Marketing - Agence Créative)</option>
<option label_1="label_2_" label_2="label_5_" id="id_38_" style="background-color:#FFD393">Didier Ouzer (Directeur Général - Agence Promotion)</option>
<option label_1="label_6_" label_2="label_4_" id="id_39_" style="background-color:#FFD393">Armando Gijon (Responsable Licence - Agence Conseil)</option>
<option label_1="label_2_" label_2="label_2_" id="id_40_" style="background-color:#FFD393">Daniel Cousin (Directeur Général - Biscuiterie)</option>
</optgroup>
</select></BODY></HTML>
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.