Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > preventing accidental form submission

Reply
Thread Tools

preventing accidental form submission

 
 
shortbackandsides.no@spam.hairdresser.net
Guest
Posts: n/a
 
      09-27-2004
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>
 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      09-27-2004
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.
 
Reply With Quote
 
 
 
 
shortbackandsides.no@spam.hairdresser.net
Guest
Posts: n/a
 
      09-27-2004
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.

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      09-28-2004
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Preventing duplicate form submission Oleg Konovalov Java 14 12-06-2006 02:22 AM
Preventing duplicate form submission Oleg Konovalov Javascript 8 12-05-2006 07:12 PM
Accidental Reverse order String display Roedy Green Java 9 08-11-2005 01:30 PM
Preventing a 2nd form submission CJM ASP General 8 06-14-2005 07:20 PM
Form Submission: Final URL that has form options included ?? Jared Javascript 5 07-10-2003 10:33 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57