Posted By:
Anin_Mathen
Posted On:
Friday, January 2, 2004 09:33 AM
Abhishek,
For Select objects that can have multiple selections (that is, the SELECT tag has the MULTIPLE attribute), the selectedIndex property is not very useful. In this case, it returns the index of the first selection. To find all the selected options, you have to loop and test each option individually. For example, to print a list of all selected options in a selection list named mySelect, you could use code such as this:
document.write("You've selected the following options:
")for (var i = 0; i < mySelect.options.length; i++)
{
if (mySelect.options[i].selected)
document.write(" mySelect.options[i].text
")
}
Hope this helps.