[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

use Enter key instead of tab key

Posted on 2004-10-18
4
Medium Priority
?
189 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
  • 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

834 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