Form onsubmit is not working ..!!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    Form onsubmit is not working ..!!!!

    [CODE=HTML]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitl ed Document</title>
    <script type="text/javascript">
    function validate(){
    alert('Yahoo... !!!');
    return false;
    }
    </script>
    </head>

    <body>
    <form onSubmit="retur n validate()">
    <input type=button value=submit onclick="this.f orm.submit()"/>
    </form>
    </body>
    </html>
    [/CODE]


    The function validate is not working ..!!!!!!!
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    onsubmit occurs when a submit button is clicked. That's just a normal button.

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      a further note: "onsubmit" and "onSubmit" is not the same in XHTML. for events it is best to use only lower case attributes. (and IE can't properly handle XHTML)

      Comment

      • Ferris
        New Member
        • Oct 2007
        • 101

        #4
        you can use HTML submit element to post the form.

        change
        Code:
        <input type=button value=submit onclick="this.form.submit()" />
        into
        Code:
        <input type="submit" value="submit" />

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by acoder
          onsubmit occurs when a submit button is clicked. That's just a normal button.
          But Acoder i am submitting the form then why it shouldn't work ?

          Comment

          • Ferris
            New Member
            • Oct 2007
            • 101

            #6
            The submit method does not invoke the onsubmit event handler. Call the onsubmit event handler directly.

            Code:
                  <form onSubmit="return validate();">
                  <input type=button value=submit onclick="this.form.onsubmit();"/>
                  </form>

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by dmjpro
              But Acoder i am submitting the form then why it shouldn't work ?
              I'll repeat what I said again highlighting the important points:

              onsubmit occurs when a submit button is clicked. That's just a normal button. Calling the submit() method is not the same as clicking the submit button.

              Comment

              Working...