Advertise with us

How to get previous selection of dropdown value when I click button?

Hi Expert!

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?

Thank in advance!

Last updated:4/8/2013 7:38:08 AM

1 Answers

AVADHESH PATEL
AVADHESH PATEL

Hi Ezra!

Try as following line of 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 for you!

Answer