Submit form

Discussion in 'ASP General' started by CJM, Jul 18, 2005.

  1. CJM

    CJM Guest

    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

    --

    [remove the obvious bits]
    CJM, Jul 18, 2005
    #1
    1. Advertising

  2. CJM

    Roland Hall Guest

    "CJM" wrote in message news:...
    : 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
    Roland Hall, Jul 18, 2005
    #2
    1. Advertising

  3. CJM

    CJM Guest

    Re: Submit form with Enter key

    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?
    >
    CJM, Jul 18, 2005
    #3
  4. CJM

    Adrienne Guest

    Gazing into my crystal ball I observed "CJM" <>
    writing in news::

    > 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
    Adrienne, Jul 19, 2005
    #4
  5. Re: Submit form with Enter key

    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" <>
    | Followup-To: microsoft.public.scripting.jscript
    | References: <>
    <>
    | 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: <>
    | 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?
    | >
    |
    |
    |
    Steven Cheng[MSFT], Jul 19, 2005
    #5
  6. CJM

    CJM Guest

    Re: Submit form with Enter key

    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
    CJM, Jul 19, 2005
    #6
  7. Re: Submit form with Enter key

    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" <>
    | References: <>
    <>
    <>
    <>
    | 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: <#>
    | 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
    |
    |
    |
    Steven Cheng[MSFT], Jul 20, 2005
    #7
    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.

Share This Page