tags:

views:

52

answers:

1

I know I have a similar post, but it only answered part of my problem.

Her is my challenge to you: Can you make the alert display the correct number of characters? Even when you press backspace?

Here is the code:

jQuery('#input_Name').keydown(function(e) {
  var count = $(this).val().length;
  alert(count+1);
});

Hint: The ascii key for backspace is 8 ( if (e.keyCode != 8) )

(I'm not able to get this right)

+2  A: 
jQuery('#input_Name').keyup(function(e) {
  var count = $(this).val().length;
  alert(count)
});
Yuriy Faktorovich
Extending "this" with jQuery on every keystroke will get pretty slow. Try this instead:var count = this.value.length;
Kevin
I really thought I tested that last night, when I got an infinite loop.... Thanks.
Steven
Kevin, thanks for the tip!
Steven