How to get previous selected item and current selected item from dropdownlist using Javascript?I think, use couple of hidden fields and store previous and current value in them. When the dropdownlist value is changed, copy current hidden field value to prev. hidden field value and then replace current hidden field value with selected drop down value.But i am new to jquery.So i dont know how to work above condition.Any one know Jquery means answer me.
Asked
Active
Viewed 1,255 times
1
-
I think this is duplicate of http://stackoverflow.com/questions/4076770/getting-value-of-select-dropdown-before-change – Vladimirs Apr 05 '13 at 09:42
2 Answers
2
For current selected item this should work
var yourSelect = document.getElementById('id');
alert(yourSelect.options[yourSelect.selectedIndex].value)
For previous
<select name="test">
<option value="test1">test1</option>
<option value="test2">test2</option>
<option value="test3">test3</option>
<option value="test4">test4</option>
</select>
(function () {
var previous;
$("select[name=test]").focus(function () {
// Store the current value on focus, before it changes
previous = this.value;
}).change(function() {
// Do soomething with the previous value after the change
document.getElementById("log").innerHTML = "<b>Previous: </b>"+previous;
previous = this.value;
});
})();

Darshan
- 535
- 1
- 3
- 16
1
Use following:
document.getElementById("ddlcountry").options[document.getElementById("ddlcountry").selectedIndex].value

Saiyam
- 138
- 2
- 11