[thelist] hack to use Enter instead of Tab on forms

Peter Brunone (EasyListBox.com) peter at easylistbox.com
Wed Feb 2 21:45:21 CST 2005


	Yes, it's come up before.  I can't speak to IE/Mac, but I know
that the easiest way to do this will fail in XP SP2.

      if (window.event.keyCode == 13) { // window.event is IE object
model
         if (!isIE) e.stopPropagation();
         else {
		event.keyCode = 9;  // This line barfs in XPSP2
		event.cancelBubble = true;
		event.returnValue = false;
		}
         fieldCollection[i+1].focus();
      }

	Where the keyCode is set, it's effectively changing the pressed
key from Enter to Tab.  Too bad it doesn't work in the new, improved
Windows.  If you can just keep the event from bubbling, you should be
okay.

Good luck...

Peter

-----Original Message-----
From: thelist-bounces at lists.evolt.org On Behalf Of sbeam

A client of mine says she likes to use the number pad on her keyboard to

enter sets of numbers in a retail pricing app we've built. So she'd 
like to be able to use that little Enter key there instead of the Tab 
to cycle through form fields (These forms typically have hundreds of 
fields across multiple screens, so from a usability perspective, I can 
see the point).

Somebody else must have had this request. I'm thinking something along 
the lines of 
-----------------
// sort-of-fake JS code off the top of my head, be kind: fieldCollection
= document.getElementsByTagName('INPUT');
for (i=0; i<fieldCollection.length; i++) {
   fieldCollection[i].onKeyPress = new function (e) {
      if (e.keyCode == 'Enter') { // whatever that code is
         fieldCollection[i+1].focus();
         if (!isIE) e.stopPropagation();
         else e.cancelBubble = true;
      }
   } 
}
-----------------

should _theoretically_ work... but as we all know Enter is used to 
submit the form by default, and I have a hunch that some IE5/Mac bug is 
going to ruin my day. 

So is it a bad idea? We need the 'modern' browsers to work. Should I 
tell her its possible or say 'no way' and save a headache?

thanks

-- 

# S Beam - Web App Dev Servs
# http://www.onsetcorps.net/





More information about the thelist mailing list