-1

I found a fiddle that logs when an input field changes value. However i would like to log the new value as well. I have tried all the combinations i found online, but cant get it to work. here is a fiddle: https://jsfiddle.net/XezmB/8/

index

<input type="number" id="n" value="5" step=".5"/>

script

    $(":input").bind('keyup change click', function (e) {
    if (! $(this).data("previousValue") || 
           $(this).data("previousValue") != $(this).val()
       )
   {
        console.log("changed");           
        $(this).data("previousValue", $(this).val());
   }
        
});


$(":input").each(function () {
    $(this).data("previousValue", $(this).val());
});
Snoopy
  • 71
  • 5

1 Answers1

0

You can do that by changing the 6th line of your shared code.

From:

console.log("changed");           

To:

console.log("changed: ", $(this).val() );           
Nabeel Khan
  • 3,715
  • 2
  • 24
  • 37