NetTalk Central

Author Topic: adding javascript to make Enter as Tab key  (Read 3450 times)

JPMacDonald

  • Full Member
  • ***
  • Posts: 106
    • View Profile
    • Email
adding javascript to make Enter as Tab key
« on: July 25, 2011, 07:06:10 AM »
I added the following javascript to a web app in an attempt to make the Enter key work like the Tab key.

It almost works in that you can see it jumping to the next field (and I get the alert box if I leave that code in) but I cannot bypass the default action of submitting the form.

I'm guessing some other script is in play after mine and is processing the enter key as normal. How do I override that to get the desired effect?

Regards

Parker

function checkForEnter (event) {
  if (event.keyCode == 13) {
   currentBoxNumber = textboxes.index(this);
   if (textboxes[currentBoxNumber + 1] != null) {
      nextBox = textboxes[currentBoxNumber + 1];
      nextBox.focus();
      nextBox.select();
      alert('trying to prevent default');
      event.preventDefault();
      //return false;
   }
  }
};

$(document).ready(function() {
//Enter = Tabkey
textboxes = $("input.nt-entry");
if ($.browser.mozilla) {
   $(textboxes).keypress (checkForEnter);
   } else {
   $(textboxes).keydown (checkForEnter);
}
});

oggy

  • Full Member
  • ***
  • Posts: 219
    • View Profile
    • Email
Re: adding javascript to make Enter as Tab key
« Reply #1 on: September 27, 2011, 12:25:42 AM »
I read this topic about java Enter to Tab function. I dont know if you got this working, but if you did not...
Try this (from your original script)
function checkForEnter (event) {
  if (event.keyCode == 13) {
   currentBoxNumber = textboxes.index(this);
   if (textboxes[currentBoxNumber + 1] != null) {
      nextBox = textboxes[currentBoxNumber + 1];
      nextBox.focus();
      nextBox.select();
    alert(input.nt-enter);
// alert each entry to prevent immediately default action
// you will not see alert message, but in this way you preventing default action.
// until you hit the Enter outside nt-entry
      event.preventDefault();
      return false;
 
   }
  }
};

$(document).ready(function() {
//Enter = Tabkey
textboxes = $("input.nt-entry");
if ($.browser.mozilla) {
   $(textboxes).keypress (checkForEnter);
   } else {
   $(textboxes).keydown (checkForEnter);


Regards, Ozren
}
});