N
N
nanny_ogg2018-03-20 13:41:39
JavaScript
nanny_ogg, 2018-03-20 13:41:39

How to get its old value when input is changed?

Actually, there is an input that changes. Getting a new input value is not difficult, but I can’t figure out how to get the old value that was before entering the new one. Maybe some other event should be used?

var price = $('#product-price').val(),
          width = $('#product-width').val();

      $('#product-footage').keyup(function(){
        var footage = $('#product-footage').val();

        // 
      });

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Epifanov, 2018-03-20
@nanny_ogg

you can store the previous value in the data attribute when you get focus on the element.
implementation example

S
sgrogov, 2018-03-20
@sgrogov

Might be worth using keydown. Then event.target.valueit will store the previous value, and event.keythe input character.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question