?
Solved

use Enter key instead of tab key

Posted on 2004-10-18
4
Medium Priority
?
185 Views
Last Modified: 2010-04-06
Hi dearest expert

Currently i have a col and row which is dynamic. each col will have the delete button.
I want user to use enter key instead of tab button.
When user hit on delete button, my row will been deleted. so i want to let user skip the delete button column and directly jump to another row. how can i do that?
Below is my code . my checking on delete button seem not working.

function handleEnter (field, event) {
   var col = <%=iNoCols%>
   var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;      
            if (keyCode == 13) {
                  var i;
                  for (i = 0; i < field.form.elements.length; i++)
                        if (field == field.form.elements[i])
                              break;
                  
                  i = i + 1;
                  if ((i) % col == 0)
                  {
                        i = i + 1;
                        alert(field.form.elements[i].name);
                        if(field.form.elements[i].name=="Delete")
                        {
                        i = i+1;
                        }
                  }
      
                  field.form.elements[i].focus();
                  return false;
            }
            else
            return true;
      }      
0
Comment
Question by:babygirls
[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
  • 2
4 Comments
 
LVL 18

Expert Comment

by:arantius
ID: 12347247
Does it have to be the enter key?  If not, you can use tabindex to control which form element comes next when the tab key is pressed, to skip the delete buttons:
http://www.w3.org/TR/html4/interact/forms.html#adef-tabindex

If it has to be enter, you'll need to assign a javascript function to onkeyup of each input box (and not the delete buttons), if the key is enter (# 13) you'll need to set focus appropriately and return false, to keep the form from submitting.
0
 

Author Comment

by:babygirls
ID: 12398688
Hi arantius,

Thanks for comment
Yah, have to use enter key :(


0
 
LVL 5

Accepted Solution

by:
steve_bagnall earned 800 total points
ID: 12445523
Hi,

This checks the next element for a name of "Delete", and if it finds it focuses on the element after that.  Although this will only go to the next row based on the layout of your page.  Let me know if it doesn't work for you and give me an example of the HTML on the rest of your page.

Cheers,
Steve

function handleEnter (field, event) {

//         var col = <%=iNoCols%>

         var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

         if (keyCode == 13) {
               var i;
               for (i = 0; i < field.form.elements.length; i++) {
                     if (field == field.form.elements[i])
                   break;
        }

            i = i + 1;


            if(field.form.elements[i].name=="Delete") {
                  i = i + 1;
            }

            /*
            if ((i) % col == 0) {
                  i = i + 1;
                  alert(field.form.elements[i].name);

                  if(field.form.elements[i].name=="Delete") {
                  i = i + 1;
            }
            }
            */

            field.form.elements[i].focus();
            return false;
      } else {

            return true;
      }
}
0
 

Author Comment

by:babygirls
ID: 12562746
Thanks Steve,
Its working..
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

762 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