Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Tab on Enter

Posted on 2002-03-27
6
Medium Priority
?
694 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

650 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