Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining selected option in multiple select list 1

Status
Not open for further replies.

snotmare

Programmer
Jan 15, 2004
262
US
Greetings all!

I have an HTML select list that allows for multiple options to be selected at once. When looking at a select list and you have more than one option selected, you'll notice a very slight difference between the options you have previously selected and the most recent option you've selected. You can tell by looking at the border of the option, which should have a grey dotted box around it. I know how to determin all the options the user selected, but I want to determin which option has that distinct grey box around it (eg the last option they've selected).

Here is how I display all of the selected options.
Code:
For i = 0 To Document.getElementById("lst0").Length - 1
    If Document.getElementById("lst0").Options(i).SELECTED = True Then
       msgbox Document.getElementById("lst0").Options(i).Value
    End If
Next

Now, how can I display only the last option they selected (the one that has that grey box around it) ???

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
int iMax=-1
For i = 0 To Document.getElementById("lst0").Length - 1
If Document.getElementById("lst0").Options(i).SELECTED = True Then
msgbox Document.getElementById("lst0").Options(i).Value
End If
iMax=i
Next
when you finish the loop iMax will have the lowermost selected option
 
What if the user selects the last option, then another option a few options up? The grey box thingy not be on the last option in the list, but the last option the user selected.

Nice try though! Any other thoughts?

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
hmm cool dont you have a selectedindex change or selected event for the option? Then on that event keep on trapping the new selectedindex until he stops and that last one would be the index you need
 
chmohan, why posting VB.Net code in the VBScript forum ?
 
Thanks again for the response chmohan, at least someone is throwing out some ideas. I had thought about using the onChange event, the onClick event, or even the MouseDown event, but I still don't know how to get what was most recently selected. The only property I know of to grab what's been selected is what I posted above.

I suppose I could keep an array, and every time the user selects a new option, loop through each option in the list and compare that option to each value in the array. If there is an array value that is not selected, then that's what the user deselected. If there is an option value that is not in the array, then that is the most recently selected option and add it to the array.

The above solution would be a pain, but doable.

Does anyone know of a comprehensive list of properties, methods, etc for the <SELECT> tag that vbscript has access to?

Still stumped.

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
Thanks for the link chmohan. I still haven't found what I'm looking for, but perhaps it's because it doesn't exist :). If I do find something, I'll let you guys know.

Here's a star for your help.

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top