Reputation: 39
How to get previous selection of dropdown value when I click button. I refer below coding
$(".addToButton").live('click', function (e) {
var sel = $(this).prevAll(".addToList:first"),
val = sel.val(),
text = sel.find(':selected').text();
});
But it is not working. How should I get previous selection of dropdown value when I click button?
Upvotes: 2
Views: 291
Reputation: 9074
Try Following code:
(function () {
var prevVal;
$("select").focus(function () {
// For storing current value on focus and on change
prevVal = this.value;
}).change(function() {
// Get new value in previous varible storage
prevVal= this.value;
});
$("btnGet").click(function(){
alert("This is previous value: "+prevVal);
});
})();
Hope its helpful.
Upvotes: 0
Reputation: 33139
You cannot ask a control for a previous property value. If you need to remember it, you need to store it in a variable somewhere explicitly.
What you can do, is create a stack and then push the new value of the dropdownbox every time it changes.
Upvotes: 3