Jump to content

Javascript Timer - I have no idea where to start!


Recommended Posts

My brain hurts.. I've been trying to find a tutorial or something to teach me how to create a Javascript timer (I don't know much Javascript at all, I tend to despise it for most things but I can't avoid it for this project), but I can't find what I'm looking for.

 

Basically, I'm creating an online exam, which requires a visible countdown timer that begins at 45min with an alert at 15min and another alert at 5min. Once the timer is finished I need the page to automatically send the form and move onto the next section of the exam, or if the user moves onto the next part of the exam before the timer finishes I need to take note of how much time they spent on that section.

 

Could someone please point me to either a code generator, tutorial or help me get it started?

Link to comment
Share on other sites

You'll have to forgive me not giving you an exact working example.  Im giving you the framework you need.

 

I could give you a better code and more helpful code if i have some additional information.  where is the timer on your page?  and big is the timer section like 20x20? 40x40? 60x60? 80x80?  Also i suggest you put a clock with the timer, its very helpful in allowing a person to know the time and when they should be done.  Also what type of exam is this and whats it for?  Javascript is helpful with user-friendly functions, but there could be a security problem if you relay 100% on javascript to handle the whole timing of the exam.  Reason why i say javascript could have a security issue is cause anything and everything javascript could be hacked since its on the client user end.

 

 

// create a function to start your timer.  // page onload event works best // button onclick works well too.
var mins_limit = 45;//personally i use seconds cause its more accurate 
var limit_seconds = mins_limit*60;//see i made a seconds thingy.
var start_time = 0;//This varible is the start of the 45 minutes.

function start_timer(){

// i stopped my work here cause idk what you got to work with.  Setting a timer is easy, but you still got to output the varibles into elements/fields which with a simple timer you only need 1 output area, but if you want something a bit more like i said above it could take 4-6 id fields and a bit more functions / math / work.



}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.