Solved

use Enter key instead of tab key

Posted on 2004-10-18
4
182 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 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

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…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

696 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