2 actions in onsubmit

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • minaozoptics

    2 actions in onsubmit


    Hi,

    I have prepared a form with frontpage.

    Before submitting the form I want the user to bu sure that he ha
    completed it exactly. Sometimes people click ENTER button just t
    continue the fill next part of the form but when we clic
    ENTER,unfortuna tely, the form is submitted directly.

    So I have written a function verify with javascript.

    As following it works correctly:

    onsubmit="retur n verify()"

    So that the user needs to accept that he is OK to submit the form.

    But when I added some required parts in the form that should b
    verified the first fuction verify is no longer active.

    So how can I verify both required parts in the form and that the use
    is OK to send the form?

    Thanks so muc


    -
    minaozoptic

  • Michael Winter

    #2
    Re: 2 actions in onsubmit

    On Wed, 15 Sep 2004 12:46:57 -0500, minaozoptics
    <minaozoptics.1 cndm0@mail.foru m4designers.com > wrote:
    [color=blue]
    > I have prepared a form with frontpage.[/color]

    Did you have to? Frontpage is a plague upon the Web, spitting out badly
    malformed HTML. It would be quicker to write the page by hand, than to gut
    the trash that Microsoft products like Frontpage and Word add.

    Unless you're well-versed in HTML, I'd advise you learn to code by hand
    first and validate your pages.
    [color=blue]
    > Before submitting the form I want the user to bu sure that he has
    > completed it exactly. Sometimes people click ENTER button just to
    > continue the fill next part of the form but when we click
    > ENTER,unfortuna tely, the form is submitted directly.[/color]

    To my knowledge, I've never encountered a browser that switches fields
    with the Enter key. I've always used Tab. Users should know their browser
    well enough to know which method to use. If you are really worried about
    accidental submissions - for example, the form initiates some critical
    action - add an intermediary page that asks for confirmation. Don't rely
    on Javascript.

    [snip]
    [color=blue]
    > So how can I verify both required parts in the form and that the user is
    > OK to send the form?[/color]

    You could use:

    <form ... onsubmit="retur n verify() &amp;&amp; validate()">

    which would normally be written as

    return verify() && validate();

    If verify returns false (the user cancels), the evaluation will
    short-circuit, and the form won't be submitted. If the user does confirm,
    then validate must also return true in order for the submission to proceed.

    However, I think that the confirmation should be moved to the server, if
    you really feel it's necessary, just as server-side validation should also
    occur with client-side used just to speed things up.

    Hope that helps,
    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.

    Comment

    Working...