jQuery input value change() on keyup

Check if input value was changed on keyup immediately (with jquery):

jQuery(function($){
    $('form input').change(function() { // works when input will be blured and the value was changed
        //alert('input value changed');
        $('.log').append(' change');
    });
    $('form input').keyup(function() { // works immediately when user press button inside of the input
        $(this).change(); // simulate "change" event
    });
});
<form>
    <input type="text" placeholder="type here to test events...">
    <div class="log">log of change and keyup events. </div>
</form>

Also check how to remove text in input on focus.

VN:F [1.9.17_1161]
Rating: 0 (from 0 votes)

2 thoughts on “jQuery input value change() on keyup

  1. it doesn't work. When I enter some text and then press arrow buttons it will write that text changed but it is false.

    VA:F [1.9.17_1161]
    Rating: +2 (from 2 votes)
    • Yes, you're right, code triggers only for keyup actions.
      You may re-write your code by remembering prev string in text input and comparing it with current.
      If these strings are different, you may trigger your custom action.

      VN:F [1.9.17_1161]
      Rating: 0 (from 0 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">