ri-ciao...
ecco quello che sono riuscito a fare:
in pratica la funzione che aggiunge l'elemento selezionato prende come argomenti il nome della selectbox e quello della multiple selectbox dove mettere gli elementi. questa funziona controlla se l'elemento non é gia dentro la selectbox di destinazione, e se é il caso non aggiunge l'elemento.codice:<script language="JavaScript"> function fillMulti(caller, linked) { //Get the two selectboxes callerEl = document.getElementsByName(caller)[0]; linkedEl = document.getElementsByName(linked)[0]; //Get selected item i = callerEl.selectedIndex; o = callerEl.options; //Get text and values (because of strange problem!) cVal = o[i].value; cTxt = o[i].text //If the element is not in the multiselect, add it if (isInLinked(o[i].value, linkedEl) == false) { linkedEl.options[linkedEl.options.length]=new Option(cTxt,cVal); } } function fillMultiAll(caller, linked) { callerEl = document.getElementsByName(caller)[0]; for(i=0;i<callerEl.options.length;i++) { alert(callerEl.options[i].value) if(arguments.length>2) { if (arguments[2] != callerEl.options[i].value) { callerEl.selectedIndex = i; fillMulti(caller, linked); } } else { callerEl.selectedIndex = i; fillMulti(caller, linked); } } } //Return true if a given id is already into the given select box (multi) function isInLinked(id, linked) { var ret = false; //If it is not in the linked box, add it for (i=0;i<linked.options.length;i++) { if (linked.options[i].value == id) { ret = true; break; } } return ret; } </script>
la funzione fillMultiAll é richiamata da un checkbox. Questa funzione deve mettere tutti gli elementi da una selectbox nell'altra. Il problema é che quando questa funzione ha piu dei due argomenti dichiarati, significa che ce ne é un terzo (contenente un id per l'appunto). Questo id é da evitare, e quindi al momento in cui trova l'option con value=id non la mette...
putroppo il tutto si crasha e lo script non risponde piu.
ideee![]()
![]()
spero di essermi spiegato![]()

Rispondi quotando