Submitting Forms

Discussion in 'Javascript' started by Mtek, Jun 1, 2008.

  1. Mtek

    Mtek Guest

    Hi,

    I have a generic routine that is called by many forms, and probably by
    many browsers. The javascript performs some validation on the form
    passed in and then issues the command 'submit()'.

    I am getting an error that says "submit() is not defined"

    I'm lost. This is a generic routine, so passing in the form is a
    must.......

    Any thoughts or suggestions?

    Thanks!!

    john
     
    Mtek, Jun 1, 2008
    #1
    1. Advertisements

  2. Yes, but it usually indicates a less optimal design too. The
    recommended way is to add an onSubmit-event to the form, and then
    prevent the form to be submitted if the checks are not okay, in stead
    of executing a submit()-command when the checks _are_ okay.

    Wrong:

    <form method="get" action="script.asp">
    <input type="button" onClick="if (...) document.forms[0].submit()">
    </form>

    Right:

    <form method="get" action="script.asp"
    onSubmit="if (...) return false">
    <input type="submit">
    </form>

    The logic for the checks is then reversed.

    Hope this helps,
     
    Bart Van der Donck, Jun 2, 2008
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.