jQuery: The Write Less, Do More JavaScript Library

Getting previous value from the drop down

View: New views
2 Messages — Rating Filter:   Alert me  

Getting previous value from the drop down

by issambres :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Just starting to explore JQuery....

What I am trying to achieve is to compare previous value & selected
value of a drop down and then display a message. I am stuck as to how
I can retrieve previous value before the made the selection. Here is
what I got so far:

 jQuery(document).ready(
        jQuery("#status").change(function(){
            alert(" You are changing status to :" + this.value);
        });
    })

Re: Getting previous value from the drop down

by Karl Swedberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi there,

You're getting there. With your code, you have the changed value. Now you just need the previous value. Try something like this:

$(document).ready(function() {
  var currentVal = $('#status').val();
  $('#status').change(function() {
    var changedVal = $(this).val();
    alert('You are changing status from ' + currentVal + ' to ' + changedVal);
    currentVal = changedVal;
  });
});


--Karl
____________
Karl Swedberg




On Jul 23, 2008, at 8:50 PM, issambres wrote:


Just starting to explore JQuery....

What I am trying to achieve is to compare previous value & selected
value of a drop down and then display a message. I am stuck as to how
I can retrieve previous value before the made the selection. Here is
what I got so far:

jQuery(document).ready(
       jQuery("#status").change(function(){
           alert(" You are changing status to :" + this.value);
       });
   })

LightInTheBox - Buy quality products at wholesale price