Your question is a little unclear, do you need to find the last option in the list which is selected, or the last option that the user seleceted in the list (which could be the first option in the list or the last)?
If you need to find out the last option that the user selected, this should get you going:
[tt]
<script>
//Array to hold the previously checked indexes
var prevCheckedIndexes = new Array()
//variable to hold the index that was last selected
var lastSelected
//function to check which indexes are currently selected
function doCheck(obj){
//Array holds all index values of options that are checked
var checkedIndexes = new Array();
var checkedIndex = lastSelected;
//loop through object adding their index if the option is checked
for(i=0; i < obj.options.length; i++)
{
if(obj.options.selected == true){
checkedIndexes[checkedIndexes.length] = i;
}
}
//Now that we have all currently selected indexes we need to
//compare against those that were previously selected
for(i=0; i < checkedIndexes.length; i++){
//for each value in checkedIndexes, see if it appears in
//prevCheckedIndexes
var matched = false;
if(prevCheckedIndexes.length == 0){
checkedIndex = checkedIndexes;
}
else{
for(j=0; j < prevCheckedIndexes.length; j++){
if(prevCheckedIndexes[j] == checkedIndexes){
matched = true;
}
}
if(matched == false){
checkedIndex = checkedIndexes;
}
}
}
prevCheckedIndexes = checkedIndexes;
lastSelected = checkedIndex;
alert('You selected: ' + lastSelected);
}
</script>
[/tt]
Then add the doCheck to the onChange event of your select tag like so:
[tt]<select onChange="doCheck(this)" name="list1" multiple>[/tt]
Of course, this script doesn't take into account de-selects, so it's possible to have a lastSelected value even if nothing is currently selected. I don't know enough about your particular situation to know if this is a good or bad thing.