I want to get the previously selected value of a dropdown control using jquery or javascript.
How can i get this?
I tried with prev() selector of jquery but failed
$(ddlStatus).find("option").prev(":selected").attr("text");
if ddlStatus has items like A,B,C,D,E When the page loads B is selected but when user changes the item {let’s say) E then I want previously selected i.e B.
You could do it like this (not optimized but works):
Then, to know the previously selected anytime, you just do:
What’s good about this code is that the state is saved in the element and you don’t use global vars, so it can be applied to any number of select boxes
Hope this helps. Cheers