Solved

Tab on Enter

Posted on 2002-03-27
6
675 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

747 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

13 Experts available now in Live!

Get 1:1 Help Now