?
Solved

Tab on Enter

Posted on 2002-03-27
6
Medium Priority
?
688 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 22

Accepted Solution

by:
CJ_S earned 200 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Suggested Courses

752 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