I need to set the maximum character input for users simililar to how stackoverflow.com works. I plan on using javascript to provide feedback to the user and count the characters. Only submissions that don’t exceed the maximum character count are allowed. I don’t plan on using the xhtml input properties to limit this amount as I’ll allow overage on characters as long as they are not submitted. On the backend I’ll just set the varchar field in mysql to charmax.
Question is, how do I count character inputs, do I base it off of onkeydown() or onkeyup(). I’m not too sure why there are two functions, because a key that goes down must come up, so which one should I use to do the counting?
HTML:
JS:
Here is a fiddle demo: http://jsfiddle.net/maniator/L2LRK/