By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,300 Members | 2,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,300 IT Pros & Developers. It's quick & easy.

Submit form

P: n/a
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

--
cj*******@REMOVEMEyahoo.co.uk
[remove the obvious bits]
Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"CJM" wrote in message news:eK**************@TK2MSFTNGP15.phx.gbl...
: 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
Jul 22 '05 #2

P: n/a
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

>>>>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?

Jul 22 '05 #3

P: n/a
Gazing into my crystal ball I observed "CJM" <cj*******@newsgroup.nospam>
writing in news:eK**************@TK2MSFTNGP15.phx.gbl:
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.

--
Adrienne Boswell
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
Jul 22 '05 #4

P: n/a
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" <cj*******@newsgroup.nospam>
| Followup-To: microsoft.public.scripting.jscript
| References: <eK**************@TK2MSFTNGP15.phx.gbl>
<uS**************@TK2MSFTNGP09.phx.gbl>
| 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: <OP**************@TK2MSFTNGP14.phx.gbl>
| Newsgroups: microsoft.public.inetserver.asp.general
| NNTP-Posting-Host: hex-it.hexadex.net 193.130.80.189
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP14.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?
| >
|
|
|

Jul 22 '05 #5

P: n/a
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
Jul 22 '05 #6

P: n/a
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" <cj*******@newsgroup.nospam>
| References: <eK**************@TK2MSFTNGP15.phx.gbl>
<uS**************@TK2MSFTNGP09.phx.gbl>
<OP**************@TK2MSFTNGP14.phx.gbl>
<YF**************@TK2MSFTNGXA01.phx.gbl>
| 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: <#L*************@TK2MSFTNGP15.phx.gbl>
| Newsgroups: microsoft.public.inetserver.asp.general
| NNTP-Posting-Host: hex-it.hexadex.net 193.130.80.189
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.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
|
|
|

Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.