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
LVL 1
mrxcolAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

smiffeCommented:
<html>
<body>
<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)
}
</script>

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

</html>

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 !
smiffeCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.