How To Get The Value Of A Field During The Paste Event?
I have a text field that I'm binding the paste event to using JQuery. When I first paste something into the form field and log its val() it returns a blank string. Likewise, if I
Solution 1:
It turns out a decent solution is to wrap the callback in a setTimeout()
, with a delay of 0 milliseconds, in order to make it asynchronous.
My new code is:
var urlField = $('#url');
urlField.bind('paste', function(e) {
setTimeout(function() {
alert(urlField.val());
}, 0); // note the 0 milliseconds
});
Thanks to DigitalBush's Masked Input Plugin, it uses this technique throughout the source.
Post a Comment for "How To Get The Value Of A Field During The Paste Event?"