Advanced Search

Results 1 to 4 of 4

Thread: JavaScript Auto Submit Form

  1. #1
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question JavaScript Auto Submit Form

    <html>
    <head>
    <script language="JavaScript" type="text/javascript">
    var t = setTimeout("document.myform.submit();",2000); //2 seconds measured in miliseconds
    </script>
    </head>
    <body>
    <form name="myform" action="nextpage.html" method="post">
    </form>
    </body>
    </html>
    That code works perfect..

    But, I wanna make an auto submit form with onClick button..it doesn't work
    <html>
    <head>
    <script language="JavaScript" type="text/javascript">
    var t = setTimeout("document.myform.submit();",2000); //2 seconds measured in miliseconds
    </script>
    </head>
    <body>
    <form name="myform" action="nextpage.html" method="post">
    <input type="name" size="12" maxlength="6" id="pswd" />
    <input type="Submit" value="LOGIN" name="value(Submit)" onclick="javascript:return Login_Form_Validator(document.parameter)" onmouseover="this.style.cursor='hand'"/>
    </form>
    </body>
    </html>
    it doesn't work anymore just because of this code :
    <input type="Submit" value="LOGIN" name="value(Submit)" onclick="javascript:return Login_Form_Validator(document.parameter)" onmouseover="this.style.cursor='hand'"/>
    if I delete this code, it works perfectly

    Can Anyone help me to solve this? thanks palz

  2. #2
    Join Date
    Nov 2008
    Posts
    58
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Default

    Why is it named 'value(Submit)'? can it be just 'submit' or 'login'?

    Try:

    Code:
     onsubmit="javascript:return Login_Form_Validator(document.parameter)
    Also see: How to Submit a Form Using JavaScript:

    javascript-coder.com/javascript-form/javascript-form-submit.phtml

    Edit: Moderator's Note:
    Although essentially correct, the advice at that link is confusing as it first mentions id to identify the form, then later shows the more cross browser method involving name. It gets worse if you're trying to validate to HTML 5 though. But that's another story.
    Last edited by jscheuer1; 01-24-2013 at 03:13 PM. Reason: format/comment

  3. #3
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    still don't work palz..
    I have change it to onsubmit..haiz

  4. #4
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    the form should be inserted inside body, and script can be execution body. so when page is loaded, it will be immediately executed:

    Code:
        <html><head></head>
    
        <body>
    
        <form action="page.php"  method="post">
        <input type="text" name="example1" value="blabla" />
        <input type="submit" />
    	</form>
    
    
        </body>
        <SCRIPT LANGUAGE=JavaScript>document.forms[0].submit();</SCRIPT>
        </html>
    Here is a working auto-submit method: when page is loaded, it will the form will be immediately autosubmited (the values can be set with php variables).
    Code:
    <form action="page.php"  method="post">
    <input type="text" name="example1" value="<?php echo $_POST['something1'];?>" />
    <input type="text" name="example2" value="ANOTHER_YOUR_VALUE" />
    <input type="submit" />
    </form>
    
    <SCRIPT LANGUAGE="JavaScript">document.forms[0].submit();</SCRIPT>
    for example, the $_POST['something1'] value is received from the previous real-user submited Form, and this form can add another input with ANOTHER_YOUR_VALUE.
    Last edited by jscheuer1; 01-24-2013 at 03:05 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •