Home > DeveloperSection > Forums > How to get previous selection of dropdown value when I click button?
ezra heywood
ezra heywood

Total Post:145

Points:1019
Posted on    April-08-2013 2:21 AM

 JavaScript JavaScript 
Ratings:


 1 Reply(s)
 1046  View(s)
Rate this:
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!



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    April-08-2013 7:38 AM

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!

Don't want to miss updates? Please click the below button!

Follow MindStick