• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2545
  • Last Modified:

Replace keyCode 13 with 9

This worked in IE9 but no longer works in IE11:
function remapEnter()
{
   if(window.event.keyCode == 13) //trap enter
   {
      if(document.activeElement.type!='textarea')  //if not textarea type
      {
         // convert to Tab key
         window.event.keyCode = 9;
         return window.event.keyCode; 
      }
   }
}

Open in new window

I want to allow users to press 'Enter' to go to the next data entry field.  Does anyone know how to get this working?
0
djpriceAtl
Asked:
djpriceAtl
  • 3
  • 2
1 Solution
 
GaryCommented:
0
 
djpriceAtlAuthor Commented:
Thanks but that is a jquery solution, I was looking more for javascript.  However, I see what you are saying that I need to change focus and not the keycode.
0
 
GaryCommented:
jQuery is javascript.  I'll try and put something together shortly.
0
 
GaryCommented:
How does this work for you
http://jsfiddle.net/evcB2/2/
Doesn't account for disabled/hidden fields

var i=0;
var els=myform.getElementsByTagName('input').length
document.onkeydown = function(e) {
    e = e || window.event;
    if (e.keyCode == 13) {
        i++;
        i>els-1?i=0:i=i;
        document.myform[i].focus();
    }
};

Open in new window

0
 
djpriceAtlAuthor Commented:
Excellent - thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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