How do i get old value and new value from jquery ui spinner after increment/decrement

1k views Asked by At

We have two input boxes..both having jquery ui spinner..depending on value of one spinner value of other spinner should change.

For e.g. First input box have value "10" Second input box has value "2"..if we increment Second input box once the value of first increments by 4 so new value of first input box will become "14" & if we decrement the value once then value of first input box decrements it will become "6"

Help how we can implement this

1

There are 1 answers

0
Runcorn On

You can use spinner spin event and use ui to get current changed value and Since, the original value is still not changed in this event you can use $(this).val() to get the old value.

 $("#spinner").spinner({
    spin : function(event,ui){
        //Gives Previous value
        console.log($(this).val());
        //Gives current value
        console.log(ui.value);
        if($(this).val()<ui.value){
            console.log("Increment");
        }else             
           console.log("decrement");
    }
});

See the Fiddle