Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Javascript - autosubmiting a form

  • 01-09-2004 05:35PM
    #1
    Subscribers Posts: 1,911 ✭✭✭


    I'm doing up a little quiz thing and I need it to auto submit after a fixed time. I've been bashing my head away at this for a few hours and I can't get it to work. What I've read up on from googled results implies the following code will work, but it fails with a 'Error: document.forms.class_test.submit is not a function' error. I've tried calling it with document.class_test.submit(), document.forms[0].submit() all with the same result. I have only a basic understanding of javascript so it's probably something simple.

    Any pointers?
    <html>
    <head>
    <script language="JavaScript">
    var i = 0;
    function setLength(len)
    {
      i = len;
    }
    
    function countDown()
    {
    if(i > 0)
    {
      i = i-1;
      window.status = i;
      var c = window.setTimeout("countDown()", 1000);
    }
    else
    {
      alert('about to try and submit');
      document.forms.class_test.submit();
    }
    }
    
    function startup(len) {
       setLength(len);
       countDown();
    }
    </script>
    </head>
    <body onload="startup(5)">
    
    <form name="class_test" action="class_test.php?module_id=26" method="post">
    This is a question<br>
    <input type ="radio" name ="answer" value ="0"> Wrong answer<br>
    <input type ="radio" name ="answer" value ="1"> Right answer<br>
    <input type="submit" name="submit" value="Submit">
    </form>
    </body>
    </head>
    


Comments

  • Registered Users, Registered Users 2 Posts: 3,209 ✭✭✭oneweb


    change
    document.forms.class_test.submit();
    to
    document.class_test.submit.click();

    alternatively, rename the submit button and use
    document.class_test.submit();

    It is what it's.



  • Moderators Posts: 6,951 ✭✭✭Spocker


    Good man oneweb, just before me.

    It's because the submit button has the name "submit" - change it to something else and it works OK.


  • Subscribers Posts: 1,911 ✭✭✭Draco


    Perfect! thanks.


Advertisement