1

The keypress doesn't detect CTRL + V when pressed on the text box. I have seen a similar post to mine. But we have different implementation. I want to trigger an ajax request if the user idle in typing for 1.5 sec.

$(document).ready( function() {
    $(document).on('keypress', '#subject-name', function() {
        updateTimeOut( this, checkSubject );
    });   
});

The method updateTimeOut() is something like this:

var updateTimeOut = function( textBoxObject, ajaxCall ) {
                         if (timeoutReference) clearTimeout(timeoutReference);
                         timeoutReference = setTimeout(function() {
                                doneTyping.call( textBoxObject, ajaxCall );
                         }, 1500);
                    };

My question is. Is't better to use change is the best for my task? Does change can also do check with interval?

Community
  • 1
  • 1
newbie
  • 1,884
  • 7
  • 34
  • 55

1 Answers1

2

Yes, you want to know when the values changes, no matter how it happens, keypress or not (e.g. right click text box and left click paste).

This should work for you

$(function() {
    $(document).on('input', '#subject-name', function() {
        updateTimeOut(this, checkSubject);
    });   
});

FYI, $(function() {}) is shorthand for $(document).ready(function() {}).

Paul Draper
  • 78,542
  • 46
  • 206
  • 285
  • The textbox is dynamically generated by `bootstrap`. Can I bind an event with that? – newbie Nov 04 '13 at 06:28
  • I see. After some research I found out that `change` event triggers only after you focus out the textbox. What should I use if I need something like all changes including when typing? – newbie Nov 04 '13 at 07:17
  • Some more research turned up the `input` event on modern browsers (not IE 8 or less). – Paul Draper Nov 04 '13 at 07:21
  • I didn't catch that. What do you mean turned up? – newbie Nov 04 '13 at 07:39