Ok if you have two arrays, compare the items in a loop. If it matches,
add it to a third array. Continue until all elements of array two have
been compared to all values in array one. The third array becomes the
items selected array

    // array index for finalArray
    var z=0;

    // origArray is items previously selected
    origArray = new Array();
    origArray[0]="1";
    origArray[1]="2";
    origArray[2]="3";
    
    // selectedArray is items newly selected
    selectedArray = new Array();
    selectedArray[0]="3";
    selectedArray[1]="4";
    
    // finalArray is to determine what has been selected
    finalArray = new Array();
    
    // loop through arrays to see what they have in common
    for (var i=0; i<origArray.length; i++){
      for (var j=0; j<selectedArray.length; j++){
        // if they match, add them to the final array
        if (selectedArray[j] == origArray[i]) 
        {
          finalArray[z] = selectedArray[j];
          // splice function will remove it from its array
          selectedArray.splice(j, 1);
            // increment index to move to next array element if
necessary
            z++;}
    }}
    // all matching entries have now been removed and we're left with
new adds
    for (var j=0; j<selectedArray.length; j++){
      // add them to the finalArray
      finalArray[z] = selectedArray[j];
        z++;
    }
    for (var y=0; y<finalArray.length; y++){
      // debug to show what we've found!
      alert ("Found it! " + finalArray[y]);
    }

Some monkeying around should get you where you need to be!

HTH,

 - Todd


-----Original Message-----
From: Howard Cheng [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, June 09, 2004 10:09 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] [Javascript] Getting index of selected item


However, consider the case where items 1, 2, and 3 are selected, then 
the use clicks item 3 only. In this case, the previously selected array 
has 3 items and the newly selected array has 1, but that one value is in

the other array, so I can't actually tell that it's been selected.

____ � The WDVL Discussion List from WDVL.COM � ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED]
       Send Your Posts To: [EMAIL PROTECTED]
To set a personal password send an email to [EMAIL PROTECTED] with the words: "set 
WDVLTALK pw=yourpassword" in the body of the email.
To change subscription settings to the wdvltalk digest version:
    http://wdvl.internet.com/WDVL/Forum/#sub

________________  http://www.wdvl.com  _______________________

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

To unsubscribe via postal mail, please contact us at:
Jupitermedia Corp.
Attn: Discussion List Management
475 Park Avenue South
New York, NY 10016

Please include the email address which you have been contacted with.

Reply via email to