added the time left info on disp question page
authornishanth
Wed, 21 Apr 2010 00:51:20 +0530
changeset 27 6233cf13fc12
parent 26 10760aa2cf52
child 28 456b7b9e3d13
added the time left info on disp question page
templates/display_question.html
--- a/templates/display_question.html	Tue Apr 20 23:59:44 2010 +0530
+++ b/templates/display_question.html	Wed Apr 21 00:51:20 2010 +0530
@@ -1,15 +1,27 @@
 {% extends 'base.html' %}
 {% block script %}
-    <script language="javascript">
-        function dipost (){
+<script language="javascript">
+		var time_left = {{question.time_limit}};
+		function dec_counter (){
+				time_left -= 1;
+				if (time_left) {
+						document.getElementById("time_left").value = "Time left: " + time_left + " secs";
+						setTimeout("dec_counter()", 1000);
+				}
+				else {
+						dopost();
+				}
+		}
+        function dopost (){
             document.getElementById("queform").submit();
         }
-		setTimeout("dipost()", {{question.time_limit}} * 1000)
+		setTimeout("dec_counter()", 1000);
     </script>
 {% endblock %}
 {% block content %}
 <form action="" method="post" id="queform">
 		{{question.description}}	<br />
-<textarea name="answer"></textarea>
+		<textarea name="answer"></textarea><br />
+		<input type="button" value="Time left: {{question.time_limit}} secs" id="time_left">
 </form>
 {% endblock %}