Solved

Tab on Enter

Posted on 2002-03-27
6
676 Views
Last Modified: 2010-05-18
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
Comment
Question by:jitganguly
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 6900421
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
 
LVL 22

Expert Comment

by:CJ_S
ID: 6900424
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
 
LVL 20

Author Comment

by:jitganguly
ID: 6900439
Any diff between two ? or EE bug ?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Accepted Solution

by:
CJ_S earned 50 total points
ID: 6900506
second code jhas the extra check && bIs which is needed :-)

CJ
0
 
LVL 20

Author Comment

by:jitganguly
ID: 6900523
Excellent. Thanx wonder boy of 20
I need to learn Javascript badly
:-)
0
 

Expert Comment

by:hilch
ID: 8522785
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Close "X" button on window popup in Firefox 7 36
javascript 5 43
Split in Javascript 5 30
CONVERT JAVASCRIPT BUTTON TO HYPERLINK TEXT 6 16
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now