1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Javascript Need Help .... Take a Review

Discussion in 'HTML & JavaScript' started by tiger56, Nov 2, 2012.

  1. tiger56

    tiger56 Registered Member

    Joined:
    Jun 28, 2011
    Messages:
    82
    Likes Received:
    7
    Hello. I have a form with submit button. I am wanted it to auto submit only once when page is loaded.

    I try this:

    Code:
    <script language="javascript">
     setTimeout('SubForm()', 30000);   // delay 3 mint
     function SubForm() { document.forms[0].submit();
     }
     </script>
    But its not working in my case because it loop every 3 mint delay.

    I need it auto submit it only once if it is not submitted with in 3 mint and than end. not loop more every 3 minit.

    Only once time submit after page load.

    (No loop, page dead after 3 mint and once submit; page dead)


    Waiting for solution and help::
     
  2. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,153
    Two things:

    a) You should pass a function reference as the first argument for setTimeout() and not a string -> setTimeout(SubForm, 30000)

    b) You should declare the function before you use it.

    c) 30000 is 30 seconds and not 3 minutes :eek: For 3 minutes you want 180000
     
  3. tiger56

    tiger56 Registered Member

    Joined:
    Jun 28, 2011
    Messages:
    82
    Likes Received:
    7
    Is there any one that can make javascript as requirement?
     
  4. CodingAndStuff

    CodingAndStuff Regular Member

    Joined:
    May 6, 2012
    Messages:
    236
    Likes Received:
    84
    Occupation:
    Swagstronaut
    Location:
    You can't have my bots. Sorry :'(
    With jQuery it's a little easier since they have nicer wrappers for everything.

    This will submit the form once the page is loaded, assuming the form's ID is "my_form".

    HTML:
    <!-- Place this first script tag between your head tags (assuming you aren't already loading jquery into the DOM) -->
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    
    <form id="my_form" action="swagger.php" method="POST">
    <!-- Your input elements here -->
    </form>
    <script type="text/javascript">
    //wait for the DOM to load
    $(document).ready(function(){
        $('#my_form').submit();
    });
    </script>
    
    You can find more documentation on hot jQuery's .submit() method works here: http://api.jquery.com/submit/