Welcome Guest, Not a member yet? Register   Sign In
Online test time counter
#1

[eluser]Unknown[/eluser]
Hi.

I'm making website with online tests, I managed to do almost all things except one.
I need to make time counter (for egxample 10 minutes) that will start counting down when test is started and when it comes to 0 test answers should be automaticly submited to database and user should be redirected to finish page.

Do you know any good way to make it ? Simple javascript countdown doesn't submit form, just redirect which is not what I need Sad Thanks in advance Smile
#2

[eluser]Andreas Karlsson[/eluser]
You _can_ submit using javascript.

Normal:
Code:
document.forms["myform"].submit();
Jquery:
Code:
$('myform').submit();
#3

[eluser]Unknown[/eluser]
Unfortunaly it doesn't work Sad Here is my code:

Js file:

Code:
/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Neill Broderick :: http://www.bespoke-software-solutions.co.uk/downloads/downjs.php */

var mins
var secs;

function cd() {
     mins = 1 * m("0"); // change minutes here
     secs = 0 + s(":21"); // change seconds here (always add an additional second to your total)
     redo();
}

function m(obj) {
     for(var i = 0; i < obj.length; i++) {
          if(obj.substring(i, i + 1) == ":")
          break;
     }
     return(obj.substring(0, i));
}

function s(obj) {
     for(var i = 0; i < obj.length; i++) {
          if(obj.substring(i, i + 1) == ":")
          break;
     }
     return(obj.substring(i + 1, obj.length));
}

function dis(mins,secs) {
     var disp;
     if(mins <= 9) {
          disp = " 0";
     } else {
          disp = " ";
     }
     disp += mins + ":";
     if(secs <= 9) {
          disp += "0" + secs;
     } else {
          disp += secs;
     }
     return(disp);
}

function redo() {
     secs--;
     if(secs == -1) {
          secs = 59;
          mins--;
     }
     document.cd.disp.value = dis(mins,secs); // setup additional displays here.
     if((mins == 0) && (secs == 0)) {
          window.alert("Time is up. Press OK to continue."); // change timeout message as required
                document.forms["testform"].submit();  
          // [removed] = "yourpage.htm" // redirects to specified page once timer ends and ok button is pressed
     } else {
         cd = setTimeout("redo()",1000);
     }
}

function init() {
  cd();
}

And this is view file

Code:
window>load->view('header') ?&gt;
    
<h1>Test Started</h1>

&lt;form name="cd"&gt;
&lt;input id="txt" readonly="true" type="text" value="10:00" border="0" name="disp"&gt;
&lt;/form&gt;

&lt;?php
$q = "";
$counter = 0;
$attributes = array('name' => 'testform', 'id' => 'testform');
?&gt;

&lt;?=form_open('test/submit', $attributes) ?&gt;
&lt;?php foreach($questions as $question): ?&gt;
<p><strong>


&lt;?php
if ($question->questioncontent != $q)
{
    echo $question->questioncontent;
    $q = $question->questioncontent;
    $counter++;
}

?&gt;

</strong></p>
&lt;?=form_checkbox($question->id.'[]', $question->answer_id) ?&gt;
&lt;?=$question->answercontent ?&gt;
&lt;?php endforeach; ?&gt;
<br /><br />
&lt;?=form_submit('submit', 'submit') ?&gt;
&lt;?=form_close() ?&gt;
&lt;?php $this->load->view('footer') ?&gt;

The timer counts down to 0, it show popup message but it doesn't do submit. Page just stand still
#4

[eluser]InsiteFX[/eluser]
You need to setup a javascript event to fire at the time you specify.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB