You must include an id attribute or the code will not work. You do not need a name attribute unless this is a form variable which will be submitted.

Points of Interest

This function was written using the Internet Explorer event model as the Light Weight Report Writer targeted ASPX applications and most of those are written for the Internet Explorer browser.If anyone converts the code to a cross browser environment, please let me know and I'll repost the source and give credit to the author.

There are a couple of issues that have to be addressed for cross-browser support.

You can pass the event from html by using the event keyword in all browsers. It's not the prferred way to do it, but is might be more compatible with your intended user base.

The keydown events are the biggest problem. Keys like the fullstop have different codes across different browsers. The Javascript Madness: Keyboard Events[^] article does a good job of explaining the problem.

The solution is to set the event on keypress instead. When you do that the navigation keycodes won't be required anymore, and you can use String.fromCharCode(event.keyCode) to retrieve the key that was pressed as a normal string character.