473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

135 100+
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

patelxxx
Aug 24 '07 #1
13 10325
epots9
1,351 Expert 1GB
heres an example of a clock, u can build on that.

good luck
Aug 24 '07 #2
patelxxx
135 100+
thank you for that.

cheers
Aug 25 '07 #3
patelxxx
135 100+
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. }
  14.  
  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.

cheers
Aug 25 '07 #4
acoder
16,027 Expert Mod 8TB
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
patelxxx
135 100+
and how would I disable the submit button once the 500 ms are over?

cheers
Aug 26 '07 #6
acoder
16,027 Expert Mod 8TB
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
patelxxx
135 100+
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
acoder
16,027 Expert Mod 8TB
Show your code so far.
Aug 27 '07 #9
patelxxx
135 100+
Expand|Select|Wrap|Line Numbers
  1. function disable_submit_button() {
  2.     alert("Time Out");
  3.     get_results();
  4.     document.getElementById("submit").disabled=true;
  5. }
  6.  
  7.  
  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"); 
  11.  
  12.  
  13. }
Aug 28 '07 #10
acoder
16,027 Expert Mod 8TB
Where's your countdown code? The clock code was in the right direction. You'll need two setIntervals. One for the disabling and the other for the countdown. Don't forget to clear the interval using clearInterval once you get to 0.
Aug 28 '07 #11
patelxxx
135 100+
Cheers for that, all ok.
Aug 30 '07 #12
acoder
16,027 Expert Mod 8TB
Cheers for that, all ok.
Glad you got it all working. Post again anytime should you hit any more problems.
Aug 30 '07 #13
Heya patelxxx
plz can you show your full code here, i am a beginner and don't know much.
www.jaipurcoaching.com
Sep 1 '11 #14

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

Similar topics

2
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 ? ...
2
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...
3
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...
19
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. ...
1
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,...
2
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...
2
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...
2
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...
3
missshaikh
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.