Skip to content Skip to sidebar Skip to footer

Track/Observe TextBox Value Changed

Is there is any way to detect text box value changed , whether users changes it explicitly or some java script code modified the text box? I need to detect this change.

Solution 1:

To track for user changes you can add a handler for key presses:

$(selector).keypress(function() {
    // your code
});

Update: besides watching for key presses, you can use the change function to watch from changes via JavaScript. It won't work immediatly for user changes (is only called after the input loses focus), but together with the keypress I believe you cover all cases:

$(selector).change(function() {
    // the same code
});

setTimeout(function() { $(selector).val("changed"); }, 2000); // Will trigger the change

Edit: sorry, it seemed to work for JavaScript too, but I was mistaken... This question, however, will be able to solve your problem (tested with setTimeout, and it was able to detect the change).

I posted an example in jsFiddle. With this new watch plugin, you no longer need keypress or change: it will work for key typing, copy/pasting, JavaScript, etc.


Post a Comment for "Track/Observe TextBox Value Changed"