disabling the ENTER button to trigger a button?

Discussion in 'HTML' started by paul814@excite.com, May 15, 2008.

  1. Guest

    Hello,
    I've got an online form, with textboxes and drop downs and at the end
    a SUBMIT button.

    My users are used to hitting ENTER to move from field to field, and
    right now if they hit ENTER, the button is executed, or the .php page
    post action is executed.

    Is there a way to disable this so the only way the post action will
    occur is if the button is clicked? how?

    thanks.
     
    , May 15, 2008
    #1
    1. Advertising

  2. Scripsit :

    > My users are used to hitting ENTER to move from field to field,


    They have to learn to abandon such habits when filling out forms on the
    web, since in most situations, Enter submits the form.

    Do you want to slow down their learning process?

    > and
    > right now if they hit ENTER, the button is executed, or the .php page
    > post action is executed.


    Right.

    > Is there a way to disable this so the only way the post action will
    > occur is if the button is clicked? how?


    Not really, and you don't want that. What would those people do who have
    no mouse to click with or have some disability that prevents them using
    the mouse "normally"?

    But taking "clicking" abstractly enough, it's a reasonable goal, but
    it's possible to a limited extent only.

    This used to be a FAQ, in the old days when FAQs flourished, the climate
    was mild and pleasant, people acted reasonably etc. You could still dig
    up some dusty old FAQ and follow some links and finally find this:
    http://www.cs.tut.fi/~jkorpela/forms/enter.html
    which explains:

    Include the following element into the head part of your document:

    <script type="text/javascript">
    function noenter() {
    return !(window.event && window.event.keyCode == 13); }
    </script>

    Add the following attribute into each input type="text" tag(s) in your
    form:
    onkeypress="return noenter()"

    It might just work, part of the time.

    --
    Jukka K. Korpela ("Yucca")
    http://www.cs.tut.fi/~jkorpela/
     
    Jukka K. Korpela, May 15, 2008
    #2
    1. Advertising

  3. Jukka K. Korpela wrote:
    > Scripsit :



    >> right now if they hit ENTER, the button is executed, or the .php page
    >> post action is executed.


    >
    > Include the following element into the head part of your document:
    >
    > <script type="text/javascript">
    > function noenter() {
    > return !(window.event && window.event.keyCode == 13); }
    > </script>
    >
    > Add the following attribute into each input type="text" tag(s) in your
    > form:
    > onkeypress="return noenter()"
    >
    > It might just work, part of the time.
    >


    As Jukka says, any JavaScript solution will only work *some* of the
    time. In the end what you need to do is have your receiving script check
    for missing required fields, and if empty, return to the fill in form
    with error message about the missing fields.

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, May 15, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yuval Kordov

    How to get enter key to trigger button click event/postback

    Yuval Kordov, Jan 7, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    445
    Yuval Kordov
    Jan 7, 2004
  2. Guest
    Replies:
    2
    Views:
    1,601
    Guest
    Oct 25, 2004
  3. Matt
    Replies:
    1
    Views:
    510
    Michael Winter
    Mar 6, 2004
  4. Replies:
    1
    Views:
    168
    marss
    Aug 11, 2006
  5. HopfZ
    Replies:
    0
    Views:
    576
    HopfZ
    Aug 28, 2006
Loading...

Share This Page