Hi all! I created a online quiz which is pagination format and contains a javascript timer. the problem is when the next page is selected the timer gets refreshed with original time. but i want that timer should start with remaining time . Plzzz help!
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<title> Quiz</title>
</head>
<body onload="var e=document.getElementsByTagName('input');var i=0;while(i<e.length){if(e[i++].type=='radio'){e[i].checked=false;}}">
<div style="font-weight: bold" id="quiz-time-left"></div>
<script type="text/javascript">
var total_seconds =60*10; /////for changing time change value of 10
var c_minutes = parseInt(total_seconds/60);
var c_seconds = parseInt(total_seconds%60);
function CheckTime()
{
document.getElementById("quiz-time-left").innerHTML
='Time Left:' +c_minutes + ' minutes ' + c_seconds + 'seconds';
if(total_seconds <=0)
{
document.forms["myform"].submit();
}
else{
total_seconds = total_seconds -1;
c_minutes = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
setTimeout("CheckTime()",1000);
}
}
setTimeout("CheckTime()",1000);
</script>
<div id="box1">
<?php
error_reporting(0);
mysql_connect("127.0.0.1","root","")or die ("Could not connect to server");
mysql_select_db("quiz")or die("Could not connect to database");
$page=$_GET["page"];
if($page=="" || $page=="1")
{
$page1=0;
}
else{
$page1=($page*1)-1;
}
$data = mysql_query("SELECT * FROM quiz limit $page1,1");
while($row = mysql_fetch_assoc($data))
{
$question_id = $row['Question_id'];
$question = $row ['Question'];
$answer1 = $row['Answer1'];
$answer2 = $row['Answer2'];
$answer3 = $row['Answer3'];
$answer4 = $row['Answer4'];
$correct = $row['Correct'];
if(empty($answer1))
{
echo"
<div id= 'box'>
<form action='quiz.php' method='POST' id='myform'>
<h3>$question_id)
$question
<ol type='A'>
<h4><li><input type='radio' name='".$question_id."' value='".$answer2."'>$answer2
<li><input type='radio' name='".$question_id."' value='".$answer3."'>$answer3
<li><input type='radio' name='".$question_id."' value='".$answer4."'>$answer4
</h4></ol></div><br>
";
}
elseif(empty($answer2))
{
echo"
<div id= 'box'>
<form action='quiz.php' method='POST' id='myform'>
<h3>$question_id)
$question
<ol type='A'>
<h4><li><input type='radio' name='".$question_id."' value='".$answer1."'>$answer1
<li><input type='radio' name='".$question_id."' value='".$answer3."'>$answer3
<li><input type='radio' name='".$question_id."' value='".$answer4."'>$answer4
</h4></ol></div><br>
";
}
elseif(empty($answer3))
{
echo"
<div id= 'box'>
<form action='quiz.php' method='POST' id='myform'>
<h3>$question_id)
$question
<ol type='A'>
<h4><li><input type='radio' name='".$question_id."' value='".$answer1."'>$answer1
<li><input type='radio' name='".$question_id."' value='".$answer2."'>$answer2
<li><input type='radio' name='".$question_id."' value='".$answer4."'>$answer4
</h4></ol></div><br>
"; }
elseif(empty($answer4))
{
echo"
<div id= 'box'>
<form action='quiz.php' method='POST' id='myform'>
<h3>$question_id)
$question
<ol type='A'>
<h4><li><input type='radio' name='".$question_id."' value='".$answer1."'>$answer1
<li><input type='radio' name='".$question_id."' value='".$answer2."'>$answer2
<li><input type='radio' name='".$question_id."' value='".$answer3."'>$answer3
</h4></ol></div><br>
";
}
else{
echo"
<div id= 'box'>
<form action='quiz.php' method='POST' id='myform'>
<h3>$question_id)
$question
<ol type='A'>
<h4><li><input type='radio' name='".$question_id."' value='".$answer1."'> $answer1
<li><input type='radio' name='".$question_id."' value='".$answer2."'> $answer2
<li><input type='radio' name='".$question_id."' value='".$answer3."'> $answer3
<li><input type='radio' name='".$question_id."' value='".$answer4."'> $answer4
</h4>
</ol>
</div>
<br>
";
}
}
$result=mysql_query("select * from quiz");
$count=mysql_num_rows($result);
$a=16;
echo"<br>" ;echo"<br>";
for($i=1;$i<=$a;$i++)
{
?> <a href="index.php?page=<?php echo $i; ?>"> <?php echo $i."";?></a><?php
}
?>
<button class="button">Submit</button>
</body>
</div>
</head>
</html>