Keypress Capture

oi ppl. I need to catch a 'backspace' keypress on a webpage....any ideas how?

Who is Participating?
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.

Michel PlungjanIT ExpertCommented:

Are you trying to prevent the backspace button from going back to the previous page?
To prevent the backspace button from doing a history.back() in IE4+:

function myKeyDownHandler()
      case(8):  // backspace
         window.event.keyCode = 0;

Then set the onKeyDown handler of whatever form element you want to point to the function above.

The alert capture different parameters you may want
<SCRIPT LANGUAGE="Javascript" ID="1">
  function displayCoords(e) {
      alert(e.screenX + " " + e.screenY)

<form name="xxx">
document.onkeypress= displayCoords;
<input type="text" name="per1" size="12" maxlength="12">
<input type="text" name="per2" size="12" maxlength="12">
<input type="text" name="per3" size="12" maxlength="12">


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
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

From novice to tech pro — start learning today.