dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Advance to next input field using ENTER key instead of TAB key

  1. #1
    Join Date
    Oct 2007
    Posts
    231

    Advance to next input field using ENTER key instead of TAB key

    I am using this code for advancing to next input field. I hate to press TAB key. Is there a better approach? Thanks.

    Firefox gives me an error if I use this code "Setting a property that has only a getter".

    Code:
    <td>
    <input type=text onkeydown="if(event.keyCode==13) event.keyCode=9;" value=1"  
    </td>                                                              
    <td>
    <input type=text onkeydown="if(event.keyCode==13) event.keyCode=9;" value=2"  
    </td>

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by codingisfun
    I am using this code for advancing to next input field. I hate to press TAB key. Is there a better approach? Thanks.
    Yes.

  3. #3
    Join Date
    Oct 2007
    Posts
    231
    This code works in IE but not in FF. Could someone please try to convert it? Thanks.

    Code:
    <body onkeydown="javascript:if(window.event.keyCode == 13) window.event.keyCode = 9;">
    Tried this revised code on FF and still not working.

    Code:
    <script type="text/javascript">
    function enterToTab(e) {
     var intKey = window.Event ? e.which : e.KeyCode;
            
      if(intKey == 13)
        e.returnValue = false;
     }
    </script>
    
    <body onkeydown="enterToTab(event);">

  4. #4
    Join Date
    Aug 2011
    Posts
    1
    This solution works in IE & Firefox:

    Code:
    <script type="text/javascript"> 
      function tabE(obj,e){ 
       var e=(typeof event!='undefined')?window.event:e;// IE : Moz 
       if(e.keyCode==13){ 
         var ele = document.forms[0].elements; 
         for(var i=0;i<ele.length;i++){ 
           var q=(i==ele.length-1)?0:i+1;// if last element : if any other 
           if(obj==ele[i]){ele[q].focus();break} 
         } 
      return false; 
       } 
      } 
    </script> 
    
    <form METHOD="POST">
    <input name="" type="text" onkeypress="return tabE(this,event)"><br>
    <input name="" type="text" onkeypress="return tabE(this,event)"><br>
    <input name="" type="text" onkeypress="return tabE(this,event)"><br>
    <INPUT TYPE="submit" Value="Ok">
    </form>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles