preventing accidental form submission

Discussion in 'Javascript' started by shortbackandsides.no@spam.hairdresser.net, Sep 27, 2004.

  1. Guest

    I've been having trouble preventing users pressing Enter part way down
    a form so the incomplete form gets submitted.

    I came up with a possible solution - the code below seems to work in
    both mozilla and MSIE - is this a good way to solve the problem? Is
    there a better alternative? Have I done anything stupid?

    My aim was to disable the normal submit process then use javascript to
    submit which appears to bypass that and work...

    Neither the normal submit button nor pressing Enter result in the form
    being sent (so in a real world application one would use a button
    rather than the normal submit field type).

    <HTML><HEAD><TITLE></TITLE></HEAD><BODY >
    <FORM ACTION="http://www.example.com/cgi-bin/myprogram.pl"
    METHOD="POST" name="myform" onSubmit="return false;">
    <input type="text" size="45" name="afield" value="a field" ><BR>
    <INPUT type="reset" value="Reset">
    <INPUT type="button" value="Submit (button)"
    onClick="document.myform.submit();">
    <INPUT type="submit" value="Submit (normal)" >
    </FORM></BODY></HTML>
     
    , Sep 27, 2004
    #1
    1. Advertising

  2. On Mon, 27 Sep 2004 19:48:07 GMT,
    <> wrote:

    > I've been having trouble preventing users pressing Enter part way down a
    > form so the incomplete form gets submitted.
    >
    > I came up with a possible solution - the code below seems to work in
    > both mozilla and MSIE - is this a good way to solve the problem? Is
    > there a better alternative? Have I done anything stupid?


    All you should try to do is check the values on both client and server. If
    the form seems incomplete, display it again filled with the submitted
    values and tell the user to complete the form before sending it. The user,
    having any sense, will see that pressing Enter at the time they did isn't
    a good idea, and it should be last time they do it.

    No need to confuse the issue with multiple buttons, some working and some
    not. Some dependent on scripting and some not.

    [snip]

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
     
    Michael Winter, Sep 27, 2004
    #2
    1. Advertising

  3. Guest

    On Mon, 27 Sep 2004 22:17:35 GMT, "Michael Winter"
    <> wrote:

    >On Mon, 27 Sep 2004 19:48:07 GMT,
    ><> wrote:
    >
    >> I've been having trouble preventing users pressing Enter part way down a
    >> form so the incomplete form gets submitted.
    >>
    >> I came up with a possible solution - the code below seems to work in
    >> both mozilla and MSIE - is this a good way to solve the problem? Is
    >> there a better alternative? Have I done anything stupid?

    >
    >All you should try to do is check the values on both client and server. If
    >the form seems incomplete, display it again filled with the submitted
    >values and tell the user to complete the form before sending it. The user,
    >having any sense, will see that pressing Enter at the time they did isn't
    >a good idea, and it should be last time they do it.


    I agree that is a better approach *where practicable* however it makes
    the assumption that all the fields are required to be completed, this
    is not always the case and this is the shortcoming I am trying to
    address.

    >No need to confuse the issue with multiple buttons, some working and some
    >not. Some dependent on scripting and some not.

    The example had two submit buttons in order to demonstrate the
    difference in their operation, a real-world implementation would not.
     
    , Sep 28, 2004
    #3
  4. RobG Guest

    wrote:

    >>All you should try to do is check the values on both client and server. If
    >>the form seems incomplete, display it again filled with the submitted
    >>values and tell the user to complete the form before sending it. The user,
    >>having any sense, will see that pressing Enter at the time they did isn't
    >>a good idea, and it should be last time they do it.

    >
    >
    > I agree that is a better approach *where practicable* however it makes
    > the assumption that all the fields are required to be completed, this


    Not at all. Mike is saying check the values on the client
    to prevent a wasted trip to the server. If the user doesn't
    have javascript enabled, you have to rely on server-side
    validation and response.

    His comment regarding "tell the user to complete the form
    before sending it" is in the context of telling the user to
    complete all mandatory fields, I don't think he means they
    must complete every field necessarily. Hopefully you have
    on-screen help and tips so that the user knows which fields
    are mandatory and those that aren't and are guided as to
    correct formats, etc.

    Cheers, Rob.
     
    RobG, Sep 28, 2004
    #4
    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. Roedy Green
    Replies:
    9
    Views:
    1,650
    Jeff Schwab
    Aug 11, 2005
  2. Wim Roffal

    accidental chinese char

    Wim Roffal, Nov 13, 2003, in forum: HTML
    Replies:
    11
    Views:
    678
    Leif K-Brooks
    Nov 13, 2003
  3. Oleg Konovalov

    Preventing duplicate form submission

    Oleg Konovalov, Oct 31, 2006, in forum: Java
    Replies:
    14
    Views:
    1,377
  4. CJM

    Preventing a 2nd form submission

    CJM, Jun 13, 2005, in forum: ASP General
    Replies:
    8
    Views:
    184
    Bob Barrows [MVP]
    Jun 14, 2005
  5. Oleg Konovalov

    Preventing duplicate form submission

    Oleg Konovalov, Oct 31, 2006, in forum: Javascript
    Replies:
    8
    Views:
    195
Loading...

Share This Page