Keypress Capture

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


Thanks,
[CriTteR]
CritAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
sandhrConnect With a Mentor Commented:
The alert capture different parameters you may want
<html>
<head></head>
<SCRIPT LANGUAGE="Javascript" ID="1">
 
  function displayCoords(e) {
    alert(String.fromCharCode(e.which));
      alert(e.screenX + " " + e.screenY)
      alert(e.target.name)
  }

</script>
<body>
<form name="xxx">
<script>
document.captureEvents(Event.KEYPRESS);
document.onkeypress= displayCoords;
</script>
<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">

</form>
</body>
</html>
0
 
Michel PlungjanIT ExpertCommented:
Nope...

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

function myKeyDownHandler()
{
   switch(window.event.keyCode)
   {
      case(8):  // backspace
      {
         window.event.keyCode = 0;
         return(false);
      }
   }
   return(true);
}


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

_________________________________________________________________________________
0
All Courses

From novice to tech pro — start learning today.