faqts : Computers : Programming : Languages : JavaScript : Event handling

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

22 of 93 people (24%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

How I can use Arrow key to move to next or previous fields in a form instead of using Tab key

May 21st, 2001 05:28
Colin Fraser, Alok Mishra,


Try this to capture the key presses and get the values of the actual key 
presses. From there the answer becomes obvious.  
<script><!--//
function netscapeKeyPress()
if (e.modifiers == 0) {
         alert("Key that was pressed has an ASCII-value of: " + 
e.which);
 }
 if (navigator.appName == 'Netscape') {
     window.captureEvents(Event.KEYPRESS);
     window.onKeyPress = netscapeKeyPress;
 }
//and for IE it reads 
function microsoftKeyPress() {
  var pressed=(window.event.keyCode)
  alert("Key that was pressed has an ASCII-value of: " + pressed);  
}
//-->
</script>
<body onKeyPress="microsoftKeyPress()"> 
This should all work to produce the codes you require for all keystrokes 
that do not use shift or ctrl keys, they are handled differently. You 
are in for a surprise though.