[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 700
  • Last Modified:

Tab on Enter

I have this function for tabbing on fields if he/she presses enter key.

function tabOnEnter (field, evt) {
       var keyCode = document.layers ? evt.which : document.all ?
     evt.keyCode : evt.keyCode;
       if (keyCode != 13)
         return true;
       else {
                 getNextElement(field).focus();
         return false;
       }
     }
function getNextElement (field) {
       var form = field.form;
       for (var e = 0; e < form.elements.length; e++)
         if (field == form.elements[e])
             break;
       return form.elements[++e % form.elements.length];
     }

and I call it like
<input name="varTests_curr(<%=i%>)" style="text-align: Right" size="10" value="<%=tests_curr(i)%>"
                    onBlur="FValidate(this);" onkeydown="return tabOnEnter (this, event);">

But I have some hidden columns on the form which are failing , like if I have
<input type="hidden" name="varTest_type(<%=i%>)" value="OCT">
after the above input it fails with an error message.
I tried to do a
if (form.elements[e].type = 'hidden')
               continue;

But its not working.
Any suggestions ?
0
jitganguly
Asked:
jitganguly
  • 3
  • 2
1 Solution
 
CJ_SCommented:
function getNextElement (field)
{
      var frm = field.form;
      var bIs = false;
      for (var e=0;e<frm.length;e++)
      {
        if(frm.elements[e].type!="hidden") return frm.elements[e];

        if (field == frm.elements[e]) bIs=true;
      }
}
0
 
CJ_SCommented:
or shorter (and I made a mistake!)

function getNextElement (field)
{
     var frm = field.form;
     var bIs = false;
     for (var e=0;e<frm.length;e++)
     {
       if(frm[e].type!="hidden" && bIs) return frm.elements[e];
       if (field==frm[e]) bIs=true;
     }
}
0
 
jitgangulyAuthor Commented:
Any diff between two ? or EE bug ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
CJ_SCommented:
second code jhas the extra check && bIs which is needed :-)

CJ
0
 
jitgangulyAuthor Commented:
Excellent. Thanx wonder boy of 20
I need to learn Javascript badly
:-)
0
 
hilchCommented:
Wouldn't it be easier simply to change the ENTER key into a TAB and then go on?

function tabOnEnter (field, evt) {
  var keyCode = document.layers ? evt.which : document.all ?
  evt.keyCode : evt.keyCode;
  if (keyCode == 13) {
    evt.keyCode = 9; // change ENTER to TAB and go on
    return true;
  }
}
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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