[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

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
0
mrxcol
Asked:
mrxcol
  • 2
1 Solution
 
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.
0
 
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 !
0
 
smiffeCommented:
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now