Reputation: 8319
i have a drop down menu, on clicking any item from the list i want to get the previously selected item. Is it possible using javascript?
Upvotes: 1
Views: 4856
Reputation: 178011
You mean
<script>
var selHistory =[];
var sel;
window.onload=function() {
sel = document.getElementById('selID');
sel.onchange=function() {
selHistory[selHistory.length]=sel.selectedIndex;
}
sel.onchange(); // save the current option
}
function getPrev() {
return (selHistory.length < 1) ? "no previous":sel.options[selHistory[selHistory.length-2]].value
}
</script>
or perhaps
<select onChange="var prevSel=(this.selectedIndex>0) ? this.options[this.selectedIndex-1].value:'nothing previous'">
Upvotes: 2
Reputation: 11377
You can just save selected item into some var and read from it when next item will be selected.
Upvotes: 0