Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Jan 2001
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Enabling the Enter Key

    I am new to web page development. I have a simple HTML file built with frontpage. It has two forms on it and a submit button and a reset button. Right now when Submit is clicked the forms get posted to an Active Server Page which processes them.
    My customer wants to be able enter something into the forms and use the enter key to activate the submit.
    At first I thought, I'll just give the submit button focus during the onload event for the page. But then I realized that the user could would have to move the focus with the mouse or tab key to key anything into either of the two forms, which puts us back to the original problem. I am assuming I will have to write some sort of client side javascript code but am open to any workable solution. It has to work under both Netscape 4.7 and IE 5.0.
    Anybody know how to do this? In your response please remember that I'm new to web development.

  2. #2
    KTYorke
    Guest

    Re: Enabling the Enter Key

    I know they'll get me if I get this wrong, but I think the ENTER key should already be able to do what you want. What happens if you fill out the form and press TAB until the Submit button is the focus... then press ENTER. You should even be able to jump from each text box of the form by using the TAB key.
    hope that helps.
    (for instance... I posted this without touching the mouse... I just tabbed to the Check Spelling button, pressed ENTER, then tabbed to the Post It button and pressed ENTER!)
    have fun

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Enabling the Enter Key

    There must be an easier answer out there somewhere!

    According to Microsoft Interactive Developer geektogeek, Oct. 1998:

    "GEEK Probably the easiest way to trap the Enter key and have it submit a form when one of the form's elements has the focus is to assign an onkeyup event handler for it. Here's an example:

    <form onkeyup="if (event.keyCode == 13) {ProcessForm()}" ...>

    This will invoke the ProcessForm function any time the Enter key is pressed and released while one of the form elements has the focus."

    According to Microsoft Interactive Developer geektogeek, Jan. 1998:

    "GEEK In Internet Explorer 4.0, you can use the OnKeyPress event in the document object to do this:
    <pre> <html>
    <head>
    <script language=vbscript>
    SUB document_onkeypress()
    if window.event.keyCode = 13 then
    test.submit
    end if
    END SUB
    </script>
    </head>
    <body>
    <form name=test action=test.html method=post>
    <select name=list>
    <option>Item1</option>
    <option>Item2</option>
    </select>
    <input type=submit value="Go!">
    </form>
    </body> </pre>

    Of course, I'm leaving the submit button there for users who aren't using Internet Explorer 4.0."

    Hope this helps.

Posting Permissions

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