473,573 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Timer function required (Javascript) - 120 secs to finish the quiz?

135 New Member
I'm setting up a quiz where users have 120 secs to finish a quiz, what timer function do I use and how?

After 120 secs I want to display a message, "Sorry timed out".

Thank you

Aug 24 '07 #1
13 10348
1,351 Recognized Expert Top Contributor
heres an example of a clock, u can build on that.

good luck
Aug 24 '07 #2
135 New Member
thank you for that.

Aug 25 '07 #3
135 New Member
I've been studying the 'timer' script, however i don't understand some parts, please see my commented lines:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function startTime()
  3. {
  4. var today=new Date()
  5. var h=today.getHours()
  6. var m=today.getMinutes()
  7. var s=today.getSeconds()
  8. // add a zero in front of numbers<10
  9. m=checkTime(m)
  10. s=checkTime(s)
  11. document.getElementById('txt').innerHTML=h+":"+m+":"+s
  12. t=setTimeout('startTime()',500)       //DON'T UNDERSTAND THIS
  13. }
  15. function checkTime(i)                 //DON'T UNDERSTAND THIS FUNCTION       
  16. {
  17. if (i<10) 
  18.   {i="0" + i}
  19.   return i
  20. }
  21. </script>
Also, After the 120 sec timer limit, i want to disable the submit button, how is this done.

Aug 25 '07 #4
16,027 Recognized Expert Moderator MVP
Line 12 uses setTimeout to call startTime() after 500 milliseconds which equals half a second. In this case, it might be better to use setInterval instead.

The checkTime function just adds a zero if the minutes or seconds is one digit (less than 10). This gives a more uniform display, e.g. instead of 12:5:9, you'd see 12:05:09.
Aug 26 '07 #5
135 New Member
and how would I disable the submit button once the 500 ms are over?

Aug 26 '07 #6
16,027 Recognized Expert Moderator MVP
and how would I disable the submit button once the 500 ms are over?
If your submit button looks like this:[HTML]<input type="submit" name="submit" id="submitbtn" value="Submit">[/HTML] then you can disable like this:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("submitbtn").disabled=true;
Aug 26 '07 #7
135 New Member
Ok cheers for that I have now got the disable button working via the setInterval() method and I can display the date too.

However how can I 'count down' (and display this on screen) the setInterval ().

Currently I have the setInterval() method to disable my submit button after two mins, however I wanted to display the 'count down' of the two mins on screen. So that it is easy for the user to see how long they have got left.

cheers you have have been great help so far.
Aug 26 '07 #8
16,027 Recognized Expert Moderator MVP
Show your code so far.
Aug 27 '07 #9
135 New Member
Expand|Select|Wrap|Line Numbers
  1. function disable_submit_button() {
  2.     alert("Time Out");
  3.     get_results();
  4.     document.getElementById("submit").disabled=true;
  5. }
  8. function set_limit() {
  9.     var limit_ques = self.setInterval("disable_submit_button()", 60000);
  10.     alert("You have 1 minute to complete the questionnaire, PRESS OK TO BEGIN"); 
  13. }
Aug 28 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Floortje | last post by:
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"...
by: DaveF | last post by:
I am trying to write a service to fire an ftp object off. I want to wait 2 minutes and then download the files. Then repeat every 2 minutes. The files just seem to stop downloading. Does that timer go off every 2 minutes if the files are done or not? Here is the code: using System; using System.Collections; using System.ComponentModel;...
by: nawhaley | last post by:
Ok I'm working on a timer that will work over multiple pages. Basically what this means is I need the timer to start on page one and give the user x amount of time to complete a quiz that spans several pages. At the end unless they completed the quiz it then pops up a message stating that they took to long to complete the quiz. I already have a...
by: arunkumar_m2001 | last post by:
Can Somebody help me to code a timed test. Actually I want to implement a timer in a web application which will pop-up an alert automatically by refreshing the web page after a specific time. Thanks Arun
by: jmgro | last post by:
I have spent way too much time trying to solve the following problem: I have a datalist with a timer in the footer template. It works wonderfully except when the user pages back, then forward, and the counter is reset. I saw in one of Kevin Spencer's comments not to put the timer in javascript on the load function, but I have to get the...
by: libsfan01 | last post by:
Hi all! I have this javascript timer which counts down the number of secs that i put in and then then redirects my page, what i want to know is how to i modify the code so that i can input the number of seconds and this creates a DISPLAY of the form MM:SS (minutes:seconds)? Which i feel is more aesthetically pleasing to the intended users of...
by: kenny | last post by:
I'm making a quiz to be posted on the internet. but I'm facing difficulties in finding a simple timer for the quiz (unlimited timing) which will keep on running regardless to the change of the page throughout the quiz. And well how to display the result of the quiz and te grade of the person who has taken the quiz....
by: HeroinNO.4 | last post by:
Copy the code below and save in a .htm file, for example : 1.htm, then run it in browser, you'll see a cool count down timer ! If it doesn't work, you may open http://www.fillweb.com in IE and View->Source, and the latest version of count down timer will show you ! <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta...
by: missshaikh | last post by:
Hi all, i need the count down timer when button click the timer start and count down work on ASP.net :( i have one timer which is on JavaScript that run page onload . but i need the Button click my code is here... <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.