Auto submit a form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NitinSawant
    Contributor
    • Oct 2007
    • 271

    Auto submit a form

    I have following HTML page created using javascript jquery,

    This doesn't work when I click on continue button,

    help

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>
    
    </title>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
        <script type="text/javascript">
            function SubmitForm() {
                //alert("hi");
                $("#frmMain").submit();
                //document.frmMain.submit();
            }
        </script>
        </head>
    <body onload="SubmitForm()">
    
            <div id="dvControls" style="display:block">
                
    <form id="frmMain" action="http://www.frendz4m.com/authenticate.php" method="POST" >
    <input type="text" name="user" value="myUsername" />
    <input type="password" name="password" value="myPassword" />
    <input type="checkbox" name="remember" value="on" />
    <input type="submit" name="submit" value="submit" />
    </form>
            </div>
            <input type="button" onclick="SubmitForm();" title="Continue" value="Continue" />
    </body>
    </html>
  • NitinSawant
    Contributor
    • Oct 2007
    • 271

    #2
    Code:
    Webpage error details
    
    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)
    Timestamp: Sat, 30 Jan 2010 10:03:11 UTC
    
    
    Message: 'document.frmMain' is null or not an object
    Line: 15
    Char: 13
    Code: 0
    URI: http://localhost:1581/SOURCE%20CODE/AutoLogin.html
    above Error is thrown in IE8 when i use "document.frmMa in.submit();"

    Comment

    • larztheloser
      New Member
      • Jan 2010
      • 86

      #3
      That's because you're using the wrong attribute. With forms, the name attribute of the form, not the id attribute, is the javascript object reference (hope that makes sense?). So if you had put this instead it should have worked:
      Code:
      <form name="frmMain" action="http://www.frendz4m.com/authenticate.php" method="POST" >

      Comment

      • NitinSawant
        Contributor
        • Oct 2007
        • 271

        #4
        changed the 'id' attribute to 'name'

        still doesn't works,

        document.frmMai n.submit();

        Comment

        • larztheloser
          New Member
          • Jan 2010
          • 86

          #5
          document.forms. frmMain.submit( );

          Comment

          • larztheloser
            New Member
            • Jan 2010
            • 86

            #6
            OR document.getEle mentById("frmMa in").submit() ;

            Comment

            • NitinSawant
              Contributor
              • Oct 2007
              • 271

              #7
              I tried following but none works

              $("#frmMain").s ubmit();
              document.frmMai n.submit();
              document.getEle mentById("frmMa in").submit() ;
              document.forms. frmMain.submit( );

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                when you change back the name attribute to the id attribute then larztheloser's suggested:
                Code:
                document.getElementById("frmMain").submit();
                has to work. as you might see this method relies on an id.

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  I think you will need to rename the submit button to something else. It probably causes a conflict because the name and method are the same.

                  Comment

                  • larztheloser
                    New Member
                    • Jan 2010
                    • 86

                    #10
                    Just tried it in your firefox and it works here! (:

                    Comment

                    Working...