Click to See Complete Forum and Search --> : 2 select boxes problem


pelegk1
07-14-2003, 01:18 AM
i have posted this problem before :
i have 2 select boxes (that u can choose more then 1 item,nd when u double click it,an item from box 1 is copied to box 2 and is deleted from box 1).
what i am doing i am reading from the cookie the things that the user has done on the page an show all of his choices!
but what happend in the 2 boxes that only the first item that was choosen is moved to the second box and all the other item's aree not!
thos is the loop i go hrough to up dat the 2 boxes(and below i wil put the code of the function that makes the movment itself :
tmpBranchSelectorList=the_info["BranchSelectorList"];
//alert("tmpBranchSelectorList :"+tmpBranchSelectorList);
count=0;
startIndex=0;
endIndex=tmpBranchSelectorList.indexOf(",",0);
BranchSelectorList=new Array();
for ( i = 0 ; i < tmpBranchSelectorList.length && count<=tmpBranchSelectorList.length/2 ; ++i ) {



if (parseInt(tmpBranchSelectorList.substring(startIndex,endIndex))>=0 && tmpBranchSelectorList.substring(startIndex,endIndex).indexOf(",",0)==-1) {
//alert("H: "+parseInt(tmpBranchSelectorList.substring(startIndex,endIndex)));
document.F1.exists.focus()
document.F1.exists.selectedIndex=parseInt(tmpBranchSelectorList.substring(startIndex,endIndex));
document.F1.exists.focus()
changeLists(document.F1.exists,document.F1.BranchesSelector);

} else break;

startIndex=endIndex+1;
endIndex=tmpBranchSelectorList.indexOf(",",startIndex+1);
count++;

}


---->>>>
the code if function changeLists():
function changeLists(list1,list2)
{


<!-- First clear the branches selector combo in case there is one ALL-->

var len2= list2.length;
if(len2>0)
{
if(list2[0].innerText.indexOf("λμ") >-1 )
{
var temp = false ;
for (r=0;r<list1.length;r++) {
if( list2[0].innerText ==list1[r].innerText)
{
temp=true ;
}
}
if(temp==false)
{
list1.add(new Option(list2[0].innerText,list2[0].value));
}
list2[0]=null;
}
}

var selectedIndex = list1.selectedIndex;
BranchSelectorList[BranchSelectorList.length]=selectedIndex;

if (selectedIndex!=-1) {
var length = list1.length;
for (j=0;j<length;j++) {
for (i=0;i<list1.length;i++) {
if (list1[i].selected==true) {

<!-- Check for ALL item in the wanted list-->
if(list1[i].innerText.indexOf("λμ") >-1 ){
var len2l = list2.length;
for(v=0;v<len2l ;v++){
list1.add(new Option(list2[0].innerText,list2[0].value));
list2[0]=null;
}
}

<!-- Check if the current item alrasy exist -->

var existitem = false ;
for (z=0;z<list2.length;z++) {
if( list2[z].innerText ==list1[i].innerText)
{
existitem =true ;
}
}

if(existitem ==false)
{
list2.add(new Option(list1[i].innerText,list1[i].value));
list1[i] = null;
i = list1.length;
break;
}
}
}
}
}
}

Khalid Ali
07-14-2003, 10:16 AM
ma shlomcha Pelegk1,

Take a look at the link below,it might give you an idea on how you can do what you want...

http://68.145.35.86/skills/javascripts/DropDownRemoveAddSelectedValues.html

pelegk1
07-15-2003, 12:45 AM
first the lonk u gave me isn't openning!
seond : i think there is a problem when i make the koop which call's the functions to move data between the 2 boxes!
maybe beacuse i do the loop it updates only once the boxes?