0

I want to be able to see new values that are entered into a text box using jQuery, one by one (character by character). I don't want the values from the text input, rather I want the value from each event, and not just the amended string from the text input.

<script type="text/javascript">
    $(document).ready(function (e){
        $("#input-text").on("input", function (e) {
            console.log(e.value);    // undefined
        });
    });
</script>

Is there a way of doing this without comparing the old value of $("#input-text") with the new one?

ryansin
  • 1,735
  • 2
  • 26
  • 49

1 Answers1

1

If you want the individual key everytime someone adds a value to the input. just use event.key

$(function() {
  $('input').on('keydown', function(event) {
    var key = event.key;
    if (key.length == 1)
      console.log("Key: ", event.key); //Gives you the individual key
    else
      console.log("Other: ", event.key);
  });
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input />
matt
  • 1,680
  • 1
  • 13
  • 16