1

I am using jQuery for my application.

I have used Keyup and Change events combined on a function. i.e. I have a textbox and whenever I type in it the word counts comes on top of it. So basically I have word count function which works on Keyup and Change events.

The problem is when I use mouse to paste some text in text box the count doesn't changes unless I press some key or I click elsewhere.

Here is my code :

events :
'keyup #IdOfTextbox'  : 'wordCounter'
'change #IdOfTextbox'  : 'wordCounter'
wordCounter() : =>
//Code for counting words in Text Box
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Arpit Rawat
  • 1,817
  • 2
  • 20
  • 28
  • possible duplicate of [How do you handle oncut, oncopy, and onpaste in jQuery?](http://stackoverflow.com/questions/237254/how-do-you-handle-oncut-oncopy-and-onpaste-in-jquery) – Merlyn Morgan-Graham Dec 14 '11 at 08:17
  • 1
    You can try binding on the 'focus', and 'paste' events. – c4urself Dec 14 '11 at 08:19
  • @c4urself seems like a good answer, you should post it as such! – Nathan Manousos Dec 14 '11 at 08:25
  • @c4urself - thanks, but its not working i have to click atleast once outside the textbox to update the word count. I am trying to make it like they have in Twitter i.e Counts get change simply by pasting some words using mouse. – Arpit Rawat Dec 14 '11 at 10:45
  • @Arpit The answer I gave, did work for me in Chrome and Firefox, which browser are you using? – c4urself Dec 14 '11 at 10:48

1 Answers1

0

Try the following:

$(document).ready(function(){
    $(".test").bind("paste keyup change", function() {
        console.log($(this).val().length);
    });
});
c4urself
  • 4,207
  • 21
  • 32