How to prevent Form submission if users hit enter.

Discussion in 'Javascript' started by Pamela Chatterjee, Oct 23, 2003.

  1. In my Web Form I have more than one Textbox for user input. If I hit
    enter to any Textbox its submitting the form. How can I prevent Form
    submission if users hit enter to the textbox? I want to submit the
    form only when user will hit submit button.

    Thanks for any help.
     
    Pamela Chatterjee, Oct 23, 2003
    #1
    1. Advertising

  2. Pamela Chatterjee

    kaeli Guest

    In article <>,
    enlightened us with...
    > In my Web Form I have more than one Textbox for user input. If I hit
    > enter to any Textbox its submitting the form. How can I prevent Form
    > submission if users hit enter to the textbox? I want to submit the
    > form only when user will hit submit button.
    >
    > Thanks for any help.
    >


    You capture the enter key.
    That's been posted on this group before, several times. Take a look at
    the archives on google. You have to worry about browsers with that one.
    So keep in mind your target browsers.

    You also break functionality a user is used to (the browser is SUPPOSED
    to do that and some people count on it) - not a good thing for general
    internet applications, acceptable for intranet apps, CD-ROMs, or
    games...
    Always remember that internet applications can be accessed by anyone
    with any browser - including those browsers modified or created for the
    disabled. Disabling functionality may render your site inaccessible to
    the disabled.

    -------------------------------------------------
    ~kaeli~
    Jesus saves, Allah protects, and Cthulhu
    thinks you'd make a nice sandwich.
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
    -------------------------------------------------
     
    kaeli, Oct 23, 2003
    #2
    1. Advertising

  3. (Pamela Chatterjee) writes:

    > In my Web Form I have more than one Textbox for user input. If I hit
    > enter to any Textbox its submitting the form. How can I prevent Form
    > submission if users hit enter to the textbox? I want to submit the
    > form only when user will hit submit button.


    Why?

    It is customary that browser forms are submitted by pressing return
    in a text field. The user will be expecting it to happen. So, why
    do you want to prevent the user from using the standard interface of
    his browser?

    If it is because you have, e.g., form validation code attached to
    the submit button, then you should move that to the form elements
    onsubmit handler instead.

    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Oct 23, 2003
    #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. William Buchanan

    Form submit in textbox when enter key hit

    William Buchanan, Apr 5, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    4,395
    William Buchanan
    Apr 7, 2006
  2. mazdotnet

    Form submission when hitting enter

    mazdotnet, Apr 20, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    380
    Steve C. Orr [MVP, MCSD]
    Apr 20, 2006
  3. CK
    Replies:
    9
    Views:
    417
    Jerry Rasmussen
    Oct 19, 2006
  4. nybble
    Replies:
    1
    Views:
    115
    Randy Webb
    Oct 2, 2005
  5. HopfZ
    Replies:
    0
    Views:
    623
    HopfZ
    Aug 28, 2006
Loading...

Share This Page