Multiple selected Indices using JS

by "Srinivasan Ramakrishnan" <srinivar(at)md3.vsnl.net.in>

 Date:  Tue, 27 Feb 2001 20:04:12 +0530
 To:  <hwg-languages(at)hwg.org>
  todo: View Thread, Original
Hi,

How do I get all the selected index values in a multiple select drop down
box using JS?

When I try accessing the 'selectedIndex' property I only get the first
selected index.

Then I tried looping through all the values using a small function like
this:

function selAlert(obj){
    selStr = "";
    for(i=0; i < obj.length; ++i)
        if(obj[i].selected)
            selStr += i + "\t";
    return selStr;
}

and I would call it like this

alert(selAlert(document.frm.drop))

where "document.frm.drop" would be the select object.

Now, this function works fine in IE5.5, and NS 4.7. I guess this should work
on IE4+ & NS4+. But then what really stumped me was Opera 5.02 was returning
even now only the first selected element's index!

How do I get the script working on Opera, and other crazy browsers? I'm
scared because I use Opera, and I hate its JS implementation.


-Srini

--
"The first steps in Agriculture, Astronomy...teach that Nature's dice are
always loaded... "

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA