How to handle which keys are pressed

This is an easy one i think. I have a form and want to be able to recognize which key was pressed. I've read that there are differences between browsers so i just need it to work in firefox (although it would be interesting to know the difference to IE).

In fact i just want to stop the user from pressing the key "comma" (,) when inside an input field. I read a lot and finally never understood how to make it work. OnKeyUp ? onKeyDown ? onKeyPress ?

Thanks a lot
Who is Participating?
<script type="text/javascript">
function noCommas(e)
var keynum

if(window.event) // IE
keynum = e.keyCode
else if(e.which) // Netscape/Firefox/Opera
keynum = e.which
return !(keynum==188)

<input type="text" onkeydown="return noCommas(event)" />


this works in firefox ie the only thing i cant figure out is how to tell if the capslock or shift key
was pushed first. this will keep commas from being entered but also the less than symbol.
mrxcolAuthor Commented:
Great, thanks !

Do you know a good site where i can find a detailed explanation about DCOM, Gecko, COM, W3C thing ? I stiull haven't managed to understand it enough.

What was driving me crazy was that window.event and e.which thing. Thanks a lot !
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.