0

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)

0

1 Answer 1

4
jQuery('#input_Name').keyup(function(e) { var count = $(this).val().length; alert(count) }); 
Sign up to request clarification or add additional context in comments.

2 Comments

Extending "this" with jQuery on every keystroke will get pretty slow. Try this instead: var count = this.value.length;
I really thought I tested that last night, when I got an infinite loop.... Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.