Solved

use Enter key instead of tab key

Posted on 2004-10-18
4
181 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 200 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Web Application Architecture 6 78
Where do I learn ES6? 3 78
What does GoogleTagMgr javascripts below do 5 33
Where does legacy ASP.NET initialize language? 2 22
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
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 learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

839 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