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