Solved

use Enter key instead of tab key

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to dynamically set the form action using jQuery.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now