Erreur à l'affichage des valeurs d'un select multiple
Bonsoir ou plutôt bonjour,
Je bloque sur la récupération des valeurs d'un select multiple1 alimenté par un autre select multiple2.
Je veux afficher les valeurs du select multiple2.
Au clique sur le bouton valider j'ai une erreur :
Code:
Erreur*: frm.liste_champs is undefined
Voici le code en entier pour le test :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| <html>
<head>
<script type="text/javascript">
function selection_champs(champs,champs_affiche){
//on récupère l'endroit sélectionner dans le select source
selection = champs.selectedIndex;
if(selection != -1){
//on déselectionne tous les champs du select de destination où va être placer le(s) champ(s) selectionner
while(champs_affiche.selectedIndex != -1){
champs_affiche.options[champs_affiche.selectedIndex].selected = false;
}
while(champs.selectedIndex > -1){
if(champs.options[champs.selectedIndex].value == "Id_type_bien"){
champs.options[champs.selectedIndex] = null;
champs.form.Id_categorie_bien.options[0].select= true;
}else{
//on cherche la place de notre champ
for(place=0;place<champs_affiche.length;place++){
if(champs_affiche.options[place].text > champs.options[champs.selectedIndex].text){
break;
}
}
//on décale tous les champs
for(i=champs_affiche.length;i>place;i--){
champs_affiche.options[i] = new Option(champs_affiche.options[(i-1)].text,champs_affiche.options[(i-1)].value);
}
//on insère le champ selectionner
champs_affiche.options[place] = new Option(champs.options[champs.selectedIndex].text,champs.options[champs.selectedIndex].value);
champs.options[champs.selectedIndex] = null;
champs_affiche.options[place].selected = true;
}
}
if(champs.length > 0){
if(selection >= champs.length ){
selection = champs.length-1;
}
champs.options[selection].selected = true;
}
}
}
function select_all(frm){
for(i=0;i<frm.liste_champs.length;i++){
frm.liste_champs.options[i].selected = true;
}
frm.liste_champs.name = "liste_champs[]";
for(i=0;i<frm.selection.length;i++){
frm.selection.options[i].selected = true;
}
frm.selection.name = "selection[]";
}
function priorite_champ(selection,mode){
if(selection.length < 2 ){return;}
old_place = selection.selectedIndex;
if(mode == 'up' && old_place > 0){
new_place = old_place-1;
}else if(mode == 'down' && old_place < selection.length-1){
new_place = old_place+1;
}
tmp = new Option(selection.options[new_place].text,selection.options[new_place].value);
selection.options[new_place] = new Option(selection.options[old_place].text,selection.options[old_place].value);
selection.options[old_place] = new Option(tmp.text,tmp.value);
selection.options[new_place].selected = true;
}
</script>
</head>
<form name="form1" method="post" action="">
<table id="tab1" cellspacing="11">
<tr>
<td>
<select id="liste_champs" multiple size="3" name="liste_champs" multiple OnDblClick="javascript:selection_champs(this.form.liste_champs,this.form.selection)">
<option>site1</option>
<option>site2</option>
<option>site3</option>
</select>
</td>
<td>
<input class="bouton" type="button" name="selectionner" value=" >> " OnClick="javascript:selection_champs(this.form.liste_champs,this.form.selection)">
</td>
<td>
<input class="bouton" type="button" name="deselect" value=" << " OnClick="javascript:selection_champs(this.form.selection,this.form.liste_champs)">
</td>
</td>
<td>
<select id="selection" name="selection" multiple size="3" class="multiple" OnDblClick="javascript:selection_champs(this.form.selection,this.form.liste_champs)">
</select>
</td>
<td>
</td>
<td>
<input type="button" name="valider" value="valider" onclick="select_all(this)">
</td>
</tr>
</table>
</form> |
Merci pour votre aide