Tuesday, December 2, 2008

onkeypress not fired for Backspace and Delete

Hi Guys,
Here is a new thing that i have come across and wanted to share.
Scenario:
I was just experimenting to show the character count dynamically when a user types text in textarea. I have called a javascript function in onkeypress event of the textarea to calculate the count and put that in a html div element using innerHTML.
Observation:
onkeypress event does not fire for Back space and Delete keys in the keyboard.
Solution:
Use both onkeypress and onkeyup events and call the same function.