HOW TO GET PREVIOUS SELECTION OF DROPDOWN VALUE WHEN I CLICK BUTTON?

ezra heywood

Total Post:145

Points:1019
Posted by  ezra heywood
 1373  View(s)
Ratings:
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!

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: How to get previous selection of dropdown value when I click button?

    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

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!