Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript pressing enter to tab won't select textfield

    I have a webpage where I have a form set up to tab to the next field when the user presses enter. The problem is that there is existing data in fields sometimes and the cursor instead of highlighting the existing text, places itself in front of the text. Not good.

    This is for a handheld scanner/pda, so the user can't hit tab or click with a mouse.

    So, the ideal situation is for when the user presses enter, that the next field is highlighted so the text can be replaced. Any ideas how I could accomplish this?

    Code for js

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    nextfield = "Product"; // name of first box on page
    netscape = "";
    ver = navigator.appVersion; len = ver.length;
    for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
    netscape = (ver.charAt(iln+1).toUpperCase() != "C");
    
    function keyDown(DnEvents) { // handles keypress
    // determines whether Netscape or Internet Explorer
    k = (netscape) ? DnEvents.which : window.event.keyCode;
    if (k == 13) { // enter key pressed
    if (nextfield == 'begin') return true; // submit, we finished all fields
    else { // we're not done yet, send focus to next box
    eval('document.yourform.' + nextfield + '.focus()');
    return false;
          }
       }
    }
    document.onkeydown = keyDown; // work together to analyze keystrokes
    if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);
    //  End -->
    </script>
    Code for textfield
    Code:
    <input name="Product" onclick="this.focus();this.select();" onFocus="nextfield ='PO';" 
    type="Text" value="<!--[CBW.Data=Product]-->" size="15">

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by uwajes
    So, the ideal situation is for when the user presses enter, that the next field is highlighted so the text can be replaced. Any ideas how I could accomplish this?
    Try using select() as opposed to focus()....

    .....Willy

  • #3
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That worked...Thanks!

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

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