Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Javascript - autosubmiting a form

Options
  • 01-09-2004 5: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 Posts: 3,137 ✭✭✭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,861 ✭✭✭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