JavaScript Timer


I have this script and i need some help numcount=0; t=setTimeout("test()",30000); document.getElementById("incrementBtn").disabled=false; timer_on = 1; function increasecounter() { timer_on = 1; numcount++; document.getElementById('countdiv').innerHTML=numcount; t=setTimeout("test()",30000); } function test() { if(timer_on) { timer_on=0; document.getElementById("incrementBtn").disabled="true"; document.getElementById("score").innerHTML = document.getElementById("countdiv").innerHTML; } } function reset() { timer_on = 0; numcount=0; document.getElementById("incrementBtn").disabled=false; document.getElementById("countdiv").innerHTML = 0; document.getElementById("score").innerHTML = ""; } New Document 0


now how do i make it so the amount of time that is left is shown in the 'time' div
if anybody could help me i would be very, very, VERY
Posted On: Monday 26th of November 2012 10:47:44 PM Total Views:  389
View Complete with Replies

RELATED TOPICS OF JavaScript PROGRAMMING LANGUAGE




Which function to use for inserting string on a timer?

I'm learning javascript. My first idea has led to a problem. I'm trying to set up strings to load at random intervals on different parts of the page, but I don't know the right function to use with setTimeout(). I hear "don't use document.write" and "probably don't use innerHTML", but are other functions outside of javascript Please help.
VIEWS ON THIS POST

144

Posted on:

Friday 16th November 2012
View Replies!

Ajax and Javascript client side timer

Hi , I have to deliver a secure web ASP.net site that after 20 minutes of inactivity wipes the users sessions and forces then to login again. I have set up all the necessary timeouts on the server and at the top of each of my master pages I have placed the following javascript: setTimeout('top.location = "login.aspx"', 1200500) The idea being that once the server has expired the session at 20mins of inactivity the browser will load in the login page. This works great until I use AJAX on my pages I suspect that as the page is only doing a partial reload, the timer keeps running as it were. My questions are:Am I correct Is there a way to reset the Client side timer through AJAX
VIEWS ON THIS POST

213

Posted on:

Monday 19th November 2012
View Replies!

ajax, timers

Hi I have a small app, my first real ajax project, which gives you details for product availability, for each day. The user selects a day (from a calendar) and then a time slot within the day. The app then displays how many slots are available for purchase, on that day, for that time... I wanted to refresh the data, every 5s, to provide slick real time availability info... but alas, when you change day (look at another day and time), the old timer still runs with the old arguments, and so it keeps resetting the 'details' panel to the previous day's details... how do I reset the timer or delete the old one
VIEWS ON THIS POST

159

Posted on:

Monday 19th November 2012
View Replies!

first timer =/

This is a basic piece of code that write a couple of links to the webpage: in the xhtml file (1.0 Strict): in the file.js file: document.write("Title"); document.write("Title"); document.write("Title"); document.write("Title"); The links aren't there, the titles are there, THERE IS NOTHING THERE!!!!! =/, Hi Jimbo, The document.write method won't work if you are using the.xhtml extention in your document. But if you want to stick using this method, then simply change your (x)HTML document using the .html extention. Good day...
VIEWS ON THIS POST

134

Posted on:

Monday 19th November 2012
View Replies!

How an External Link with timer will be Re-Directed the Outbound URL

CWA, I am not 100% sure I understand what you are asking but I did my best, so do excuse me if below has no relevance at all. From what I see you want to direct the user to 'farewell' page that will redirect them to the originally intended location 15 seconds later or when the user clicks a force-redirect link. Below is a quick application I just wrote which hopefully gives you some insight on how to achieve this! It's very basic and is only supposed to be used to educate yourself on how the process works. index.html Go to Google.com farewell.html var url_split = window.location.toString().split(''), // Split the window URL. get_headers = url_split[url_split.length-1], // Get the GET headers from the URL, the last split segement. split_headers = get_headers.split('&'), // Split all the headers. headers = [], // Create an empty array to hold the actual headers. finalLocation = 'index.html'; // A string to store the final location, set as index.html to start with incase of errors. // Let's loop the headers and put them in an array, making them easy to access. for (var header_pointer in split_headers) { var header = split_headers[header_pointer], // A single header. split_header = header.split('='); // Split the header key=>value style. headers[split_header[0]] = split_header[1]; // Push the header into the headers array. } var currentTick = 15, // 15 seconds on the timer. timer; // The coutndown display function startTimer() { setInterval(updateTimer, 1000); } function updateTimer() { if (currentTick === 0) redirect(); else { currentTick -= 1; timer.innerHTML = currentTick; } } function redirect() { window.location = finalLocation; // Redirect the user to the finalLocation, which should no longer be finalLocation } function load() { timer = document.getElementById('time'); // Set the timer object timer.innerHTML = currentTick; // Display the countdown time. finalLocation = headers.location; // Get the location header and set that to the destination. document.getElementById('link').href = finalLocation; // Update the static link. startTimer(); } window.onload = load; You will be redirected in seconds, click here if you do not want to wait!
VIEWS ON THIS POST

123

Posted on:

Monday 19th November 2012
View Replies!

java script timer

anybody tell me how to do code for timer in jsp or javascript i make a quiz of an hour . after the quiz page will redirect another quiz and take time from serverside so on refreshing time will not restart
VIEWS ON THIS POST

131

Posted on:

Wednesday 21st November 2012
View Replies!

Making this JavaScript timer reset when it's finished

Alright, I'm not very good with Javascript, in fact I just started sitting down and really trying to learn it about two weeks ago. I have a timer I got offline and have tweaked with a bit and modified to suit my needs (almost). For the last hour I've been trying to figure out how I can make this script reset itself without having to refresh the page. When the time runs out, I want it to go back to the 00:30 so that I can use it again. If anyone can help me figure out how to do this I'd appreciate it, also any additional advice you have on what I'm doing (whether you think I should do it a different way or not) is also welcomed. var mins var secs; function cd() { mins = 1 * m("0"); // change minutes here secs = 0 + s(":31"); // change seconds here (always add an additional second to your total) redo(); } function m(obj) { for(var i = 0; i < obj.length; i++) { if(obj.substring(i, i + 1) == ":") break; } return(obj.substring(0, i)); } function s(obj) { for(var i = 0; i < obj.length; i++) { if(obj.substring(i, i + 1) == ":") break; } return(obj.substring(i + 1, obj.length)); } function dis(mins,secs) { var disp; if(mins
VIEWS ON THIS POST

128

Posted on:

Wednesday 21st November 2012
View Replies!

countdown timer

cvar month = '0';// Javascript Documentvar month = '9'; // 1 through 12 or '*' within the next month, '0' for the current month var day = '27'; // day of month or + day offset var dow = 0; // day of week sun=1 sat=7 or 0 for whatever day it falls on var hour = 18; // 0 through 23 for the hour of the day var min = 0; // 0 through 59 for minutes after the hour var tz = +5.30; // offset in hours from UTC to your timezone var lab = 'cd'; // id of the entry on the page where the counter is to be inserted function start() { displayCountdown(setCountdown(month,day,hour,min,tz),lab); } loaded(lab,start); // Countdown Javascript // copyright 20th April 2005, 1st November 2009 by Stephen Chapman // permission to use this Javascript on your web page is granted // provided that all of the code in this script (including these // comments) is used without any alteration // you may change the start function if required var pageLoaded = 0; window.onload = function() { pageLoaded = 1; } function loaded(i,f) { if (document.getElementById && document.getElementById(i) != null) f(); else if (!pageLoaded) setTimeout('loaded(\''+i+'\','+f+')',100); } function setCountdown(month,day,hour,min,tz) { var m = month; if (month=='*') m = 0; var c = setC(m,day,hour,tz); if (month == '*' && c < 0) c = setC('*',day,hour,tz); return c; } function setC(month,day,hour,tz) { var toDate = new Date(); if (day.substr(0,1) == '+') { var day1 = parseInt(day.substr(1)); toDate.setDate(toDate.getDate()+day1); } else { toDate.setDate(day); } if (month == '*')toDate.setMonth(toDate.getMonth() + 1); else if (month > 0) { if (month 0) toDate.setDate(toDate.getDate()+(dow-1-toDate.getDay())%7); toDate.setHours(hour); toDate.setMinutes(min-(tz*60)); toDate.setSeconds(0); var fromDate = new Date(); fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset()); var diffDate = new Date(0); diffDate.setMilliseconds(toDate - fromDate); return Math.floor(diffDate.valueOf()/1000); } function displayCountdown(countdn,cd) { if (countdn < 0) document.getElementById(cd).innerHTML = "Sorry, you are too late."; else { var secs = countdn % 60; if (secs < 10) secs = '0'+secs; var countdn1 = (countdn - secs) / 60; var mins = countdn1 % 60; if (mins < 10) mins = '0'+mins; countdn1 = (countdn1 - mins) / 60; var hours = countdn1 % 24; var days = (countdn1 - hours) / 24; document.getElementById(cd).innerHTML = days+' days + '+hours+' : '+mins+' : '+secs; setTimeout('displayCountdown('+(countdn-1)+',\''+cd+'\');',999); } } // this code not working properly all the browser together. This post has been edited by JackOfTrades: 24 May 2010 - 04:48 AM Reason for edit:: Added code tags
VIEWS ON THIS POST

154

Posted on:

Wednesday 21st November 2012
View Replies!

Disable form until timer counts down to zero ...

I'm designing a live auction website and I need to limit the number of posts each bidder makes. My current goal is to allow one bid every 60 seconds. My concept is to allow the first post to be submitted normally, then disable the form -- specifically the submit button -- until the bidder waits for the 60 second countdown timer to expire. During the 60 seconds after each post while the countdown timer is 'counting down' I hope to display a semi-transparent countdown value (in seconds) on top of the form. When the countdown timer reaches zero the transparent timer display should disappear, then the submit button should become active again. An alternative to a transparent countdown on top of the form is to display number of seconds remaining in the submit button itself. Then when the timer reaches zero the submit button once again becomes active and displays "submit". My questions are: Can this be done entirely in javascript or will it require additional tools If it takes more than just javascript, what are the additional requirements
VIEWS ON THIS POST

136

Posted on:

Wednesday 21st November 2012
View Replies!

Are timers labor intensive on a computer?

Here's my issue, if someone stands up and walks away from their computer while logged in they are still logged in until they go to another page or refresh. I was going to write a JS script that would have a timer that would check the SESSION and if it is older than 1 hour it refreshes the page. Is that load intensive on the machine
VIEWS ON THIS POST

123

Posted on:

Thursday 22nd November 2012
View Replies!

How to disable a form when a javascript timer ends?

Is it possible to disable my submit button when my javascript timer has finished and has showed its end message. This is my form Bid Now The java script message will be Auction ended when the timer reaches a specific date.
VIEWS ON THIS POST

142

Posted on:

Saturday 24th November 2012
View Replies!

Hangman with timer and clue in javascript

please help me with this program...badly needed....
VIEWS ON THIS POST

105

Posted on:

Saturday 24th November 2012
View Replies!

timer not working!!

ki ggt
VIEWS ON THIS POST

133

Posted on:

Saturday 24th November 2012
View Replies!

Animation with timer

Code below runs well in IE only but, i need it to run on other browsers as well. If anyone have same thing for other browsers then plese help me.
VIEWS ON THIS POST

101

Posted on:

Saturday 24th November 2012
View Replies!

Hangman w/ timer

Why did you create three threads with nothing but a bunch of code and mark them all solved
VIEWS ON THIS POST

119

Posted on:

Sunday 25th November 2012
View Replies!

Create a timer for php pages

i want to create a timer for my php page i created the page that only 20 second i want that the time should be as 00:00:20 (hh:mm:ss) plz help my scipt are.......................................................................................................... Time Left: var myTime = 20; function countDown() { document.form.seconds.value = myTime; if (myTime == 0) { location.href="trivia1.php"; } else if (myTime > 0) { myTime--; setTimeout("countDown()",1000); } } countDown();
VIEWS ON THIS POST

226

Posted on:

Sunday 25th November 2012
View Replies!

Getting variable in coutdown timer

Ok, so here is what I've gathered together so far. I've got a countdown timer, that at the end of 180 seconds it executes the function clearit. The problem I'm having I would like to put a user chosen variable in place of the 180. Any help would be greatly appreciated. Thank you. function starttimer8() { /* set your parameters( number to countdown from, pause between counts in milliseconds, function to execute when finished ) */ startCountDown(180, 1000, clearit); } function startCountDown(i, p, f) { // store parameters var pause = p; var fn = f; // make reference to div var countDownObj = document.getElementById("countDown"); if (countDownObj == null) { // error alert("div not found, check your id"); // bail return; } countDownObj.count = function(i) { // write out count this.innerHTML = i; if (i == 0) { // execute function fn(); // stop return; } setTimeout(function() { // repeat countDownObj.count(i - 1); }, pause ); } // set it going countDownObj.count(i); }
VIEWS ON THIS POST

125

Posted on:

Sunday 25th November 2012
View Replies!

JS/AJAX timer

. I have a problem I can't figure out on my own. I want to create a JS/AJAX function which counts down for exactly 10 seconds (for example), and then it performs an action - calls a .php file, and loads its content in a div element. The main problem is - users can simply edit the JS and set the 10 second timer to 1 second, for example. I wonder if there is a way to work this out in JS I want the 10 seconds to be "set in stone". I guess I could achieve similar effect by using database, and comparing the time when script started/ended. Any ideas I need someone to point me in the right direction.
VIEWS ON THIS POST

124

Posted on:

Sunday 25th November 2012
View Replies!

Pausing a timer

Thanks to all that have helped with this project so far. I have one other problem I cannot figure out. How do I pause the timer so I can maintain the set time and re-start where it left off Here is most of my code, I removed most of the select options to save space: 24 hour Timer // designed by Javascript Archive, (c)1999 // Get more free javascripts at http://jsarchive.8m.com var aySound = new Array(); // Below: source for sound files to be preloaded aySound[0] = "explosion.wav"; aySound[1] = "machinegun.mp3"; // DO NOT edit below this line document.write('') IE = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all) 1:0; NS = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"]) 1:0; ver4 = IE||NS 1:0; onload=auPreload; function auPreload() { if (!ver4) return; if (NS) auEmb = new Layer(0,window); else { Str = ""; document.body.insertAdjacentHTML("BeforeEnd",Str); } var Str = ''; for (i=0;i 0) { document.getElementById("secondOutput").innerHTML-=1; window.setTimeout(function(){display(a)}, 1000); //seconds=seconds-1; } else { playSound(1); } } function pause() { } 0 Hrs Min Sec 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 , Thanks for all your help, I should be able to finish from here. If I can ever get this done, I will post the entire project as a tutorial. (This is actually being created as a Vista Gadget) Thanks again!!
VIEWS ON THIS POST

138

Posted on:

Monday 26th November 2012
View Replies!

How to make a countdown timer in DHTML

Hi I should need the code/syntax to create an countdown timer that should count down from now to (24hour)19:00 12-06-2011 do any one know how to do this
VIEWS ON THIS POST

203

Posted on:

Monday 26th November 2012
View Replies!