After timer submit form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Floortje

    After timer submit form

    Hi, im an absolute noob at javascript. I copied a timer from a site wich
    counts to 5 minutes and then pos up an alert. Is it possibel to
    automatically submit the form after I click ok ?


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitl ed Document</title>
    </head>
    <SCRIPT LANGUAGE = "JavaScript ">
    <!--
    var secs
    var timerID = null
    var timerRunning = false
    var delay = 1000

    function InitializeTimer ()
    {
    // Set the length of the timer, in seconds
    secs = 300
    StopTheClock()
    StartTheTimer()
    }

    function StopTheClock()
    {
    if(timerRunning )
    clearTimeout(ti merID)
    timerRunning = false
    }

    function StartTheTimer()
    {
    if (secs==0)
    {
    StopTheClock()
    // Here's where you put something useful that's
    // supposed to happen after the allotted time.
    // For example, you could display a message:
    alert("De tijd is voorbij. Druk op ok en daarna op opslaan")
    }
    else
    {
    self.status = secs
    secs = secs - 1
    timerRunning = true
    timerID = self.setTimeout ("StartTheTimer ()", delay)
    }
    }
    //-->
    </SCRIPT>

    <body onLoad="Initial izeTimer()" >

    <h1> Header here</h1>
    <p>text</p>
    <form name="form1" method="post" action="">
    <table width="100%" border="1">
    <tr>
    <td width="17%">pos itief</td>
    <td width="83%"><di v align="right">
    <textarea name="positief" cols="100" rows="5"
    id="positief"> </textarea>
    </div></td>
    </tr>
    </table>
    </form>
    </body>
    </html>


  • Rob B

    #2
    Re: After timer submit form



    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitl ed document</title>
    </head>
    <script type="text/javascript">

    var timerID = null;
    var startsecs = 10;
    var secs;

    function countdown()
    {
    window.status = secs-- + ' seconds remaining...';
    if (secs < 0)
    {
    clearInterval(t imerID);
    if (confirm('Submi t the form?'))
    document.getEle mentById('form1 ').submit();
    else timerinit();
    }
    }

    function timerinit()
    {
    secs = startsecs;
    countdown();
    timerID = setInterval(cou ntdown, 1000);
    }

    onload = timerinit;
    onunload = function()
    {
    if (null != timerID)
    clearInterval(t imerID);
    }

    </script>
    <body>

    <h1> Header here</h1>
    <p>text</p>
    <form id="form1" name="form1" method="post"
    action="javascr ipt:alert('subm itted')">
    <table width="100%" border="1">
    <tr>
    <td width="17%">pos itief</td>
    <td width="83%"><di v align="right">
    <textarea name="positief" cols="100" rows="5"
    id="positief"> </textarea>
    </div></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    Gave the user an opportunity to recycle the timer - you can replace
    those lines with:

    clearInterval(t imerID);
    alert('De tijd is voorbij. Druk op ok en daarna op opslaan')
    document.getEle mentById('form1 ').submit();

    Sorry, don't speak Dutch. Timers are annoying btw.


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!

    Comment

    • Floortje

      #3
      Re: After timer submit form

      > clearInterval(t imerID);[color=blue]
      > alert('De tijd is voorbij. Druk op ok en daarna op opslaan')
      > document.getEle mentById('form1 ').submit();
      >
      > Sorry, don't speak Dutch. Timers are annoying btw.[/color]

      It's for an a social psychology experiment. People have 5 minutes to
      complete a job in a small team. Then after these 5 minutes a newcomer is
      introduced to the team. If someone would take longer to complete the task
      the data cannot be compared. Otherwise I would agree .. timers are annoying
      :-)

      Floortje


      Comment

      Working...