Submitting Forms

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

    Submitting Forms


    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
  • Dan Rumney

    #2
    Re: Submitting Forms

    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?
    submit() is a method on a form object... you can't just call it on its own

    If you provide some sample code which demonstrates the problem that
    you're having, that would be helpful.

    Thanks

    Comment

    • Bart Van der Donck

      #3
      Re: Submitting Forms

      Rumney wrote:
      ??? wrote:
      >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"
      >
      submit() is a method on a form object... you can't just call it on its
      own
      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

      Comment

      Working...