Submit form

C

CJM

Can somebody clarify if/how/when a simple form is submitted when the <Enter>
key is pressed?

As I understood it, if you have a form with a single submit button, if enter
is pressed, the form should be submitted as if the button is pressed. Is
this correct?

Does this behaviour vary across browsers?

Chris
 
R

Roland Hall

in message : Can somebody clarify if/how/when a simple form is submitted when the
<Enter>
: key is pressed?
:
: As I understood it, if you have a form with a single submit button, if
enter
: is pressed, the form should be submitted as if the button is pressed. Is
: this correct?
:
: Does this behaviour vary across browsers?

I have no idea. This is how I test for it.

dim postback
postback = Request.ServerVariables("REQUEST_METHOD")
if postback = "POST" then
' process my form
end if

If you're looking for it to post on the URL then the method will be GET.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
C

CJM

I've just realised part/all of the problem... My application uses a
client-side script to validate the form inputs, before setting the Action
property of the form and submitting it. Therefore, if the button is not
pressed, the validation code is not run and the Action property is not - so
the page POSTs back to itself.

Therefore I need to be able to detect that the Enter key has been pressed,
in which case I can validate the code and submit the form accordingly. Can
anyone give me any pointers on the best way to do this?

[Follow-ups set to m.p.s.jscript]

Thanks

Chris
 
A

Adrienne

Can somebody clarify if/how/when a simple form is submitted when the
<Enter> key is pressed?

As I understood it, if you have a form with a single submit button, if
enter is pressed, the form should be submitted as if the button is
pressed. Is this correct?

Does this behaviour vary across browsers?

Chris

This _should_ work across browsers, but it always best to check server
side.
 
S

Steven Cheng[MSFT]

Hi Chris,

As for the validating form inputs and submit it question you mentioned,
here are some of my understanding and suggestions:

1. For HTML page in webbrowser, when there is some entry fields and submit
buttons, if we set focus on a certain entry field( for example input some
value in a textbox) and hit enter key, we will found the page be submited
as if one fo the submit button is clicked. At lease IE browser will behave
as this. In fact, this is because when the entry field is accepting input,
the focus of the page is on the first submit button on the form, you can
have a check on this, so when we hit enter key, the focused submit button
is clicked. Also, this is not always true when the page's structure become
very complex. And I know many guys will manually use some script to hook
the entry fields's key down event and use script to submit the form in that
event.

2. For validation the form's fields and submit it to the correct page, my
suggestion is we just submit the form to the same page self. Then in the
page's code block, we do the validation, when the input data are valid, we
use server.transfer to redirect the request to our target processing page(
the forms collection will reserve when using server.Transfer to skip from
different page). For example:

<%
dim method

method = Request.ServerVariables("REQUEST_METHOD")


if method = "POST" Then

' do the validation here
if Request.Form("username") = Request.Form("password") Then

Server.Transfer("result.asp")
else
Response.Write("Invalid input!")
end if


end if
%>

also, make sure your form's Method is set to "POST" like:

<form name="xform" action="" method="POST">

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "CJM" <[email protected]>
| Followup-To: microsoft.public.scripting.jscript
| References: <[email protected]>
<[email protected]>
| Subject: Re: Submit form with Enter key
| Date: Mon, 18 Jul 2005 12:59:23 +0100
| Lines: 32
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.inetserver.asp.general
| NNTP-Posting-Host: hex-it.hexadex.net 193.130.80.189
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.inetserver.asp.general:24670
| X-Tomcat-NG: microsoft.public.inetserver.asp.general
|
| I've just realised part/all of the problem... My application uses a
| client-side script to validate the form inputs, before setting the Action
| property of the form and submitting it. Therefore, if the button is not
| pressed, the validation code is not run and the Action property is not -
so
| the page POSTs back to itself.
|
| Therefore I need to be able to detect that the Enter key has been
pressed,
| in which case I can validate the code and submit the form accordingly.
Can
| anyone give me any pointers on the best way to do this?
|
| [Follow-ups set to m.p.s.jscript]
|
| Thanks
|
| Chris
|
|
| >>>>>>>>Original Post >>>>>>>>>>>>
| >
| > Can somebody clarify if/how/when a simple form is submitted when the
| > <Enter>
| > key is pressed?
| >
| > As I understood it, if you have a form with a single submit button, if
| > enter
| > is pressed, the form should be submitted as if the button is pressed. Is
| > this correct?
| >
| > Does this behaviour vary across browsers?
| >
|
|
|
 
C

CJM

I think I'm going to have to handle the forms onkeypress event to guarrantee
the Enter key behaviour.

As for the validation, some validation is already done server-side, but I'm
using client-side validation to give immediate feedback when some obvious
mistakes are made (ie mandatory fields not entered etc)

Chris
 
S

Steven Cheng[MSFT]

Thanks for your response.

Yes, using clientside validation will have good effect on user experience
and performance. Anyway, if there're any thing else we can help later,
please feel free to post here. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "CJM" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Submit form with Enter key
| Date: Tue, 19 Jul 2005 12:03:36 +0100
| Lines: 10
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.inetserver.asp.general
| NNTP-Posting-Host: hex-it.hexadex.net 193.130.80.189
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.inetserver.asp.general:24731
| X-Tomcat-NG: microsoft.public.inetserver.asp.general
|
| I think I'm going to have to handle the forms onkeypress event to
guarrantee
| the Enter key behaviour.
|
| As for the validation, some validation is already done server-side, but
I'm
| using client-side validation to give immediate feedback when some obvious
| mistakes are made (ie mandatory fields not entered etc)
|
| Chris
|
|
|
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top