Forum Moderators: open

Message Too Old, No Replies

Character Count onKeyDown

         

Gian04

2:01 pm on Jun 18, 2007 (gmt 0)

10+ Year Member



My existing script limit the user input to 200 chars (inc. spaces), onKeyDown

My problem is, if you mistakenly entered a character, there's no way to remove it since the backspace and the delete button on the keybord will not function also if you reached the max. # of chars.

Anyone who has a better script, and please the script with a a visible counter of the allowable remaining characters.

Thanks

penders

3:14 pm on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just a comment... I use the onkeyup event to do the same sort of thing and don't have a problem with it blocking the delete key?

Fotiman

4:19 pm on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You don't want to use onkeydown for that. Suppose you have a blank field. If the user presses and holds down a key, the onkeydown event will only be fired once, but the onkeypress event will be repeated over and over and the field will fill up with characters. They could easily exceed your 200 character limit. Instead, perform the check after the user has finished (onkeyup).