I think I've done this in the past and can't remember EXACTLY how I had
done it but you have to loop through the options to see if they are
selected.

I found this code on the net. Maybe it'll help...
var so = document.Form.select1; 
selectedOptions = new Array();
for (var i=0; i < so.length; i++){ 
if (so.options[i].selected)
{
  selectedOptions[i] = so.options[i].value;
} 
}

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


I have a multiple select box where I need to get the index of the item 
that was just selected or de-selected. Anyone know of a way to do that? 
selectObj.selectedIndex returns the index of the first selected item, 
not the one that was just clicked. This is an IE-only application so if 
perhaps there's something in the IE-specific API? I looked in the event 
object, but couldn't find anything useful.

My current approach is to fill an array on page load of what items are 
selected at load time. Then in the select box's onchange event, get the 
list of currently selected items and compare that to what was previously

selected. If one item is in the first array, but not the second, that 
means it was the one that was just clicked. This works in most cases.

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.

Anyone have any other ideas? TIA.
-- 
::::::::::::::::::::::::::::::
Howard Cheng
http://www.howcheng.com/
Wise-cracking quote goes here.

____ * 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.unsub%%

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.


____ � 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