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:second s)? Which i
feel is more aesthetically pleasing to the intended users of the site.
Kind regards
Marc
<HEAD>
<SCRIPT LANGUAGE="JavaS cript">
var start=new Date();
start=Date.pars e(start)/1000;
var counts=100; //NUMBER OF SECONDS TO COUNTDOWN FROM
function CountDown(){
var now=new Date();
now=Date.parse( now)/1000;
var x=parseInt(coun ts-(now-start),10);
if(document.for m1){document.fo rm1.clock.value = x;}
if(x>0){
timerID=setTime out("CountDown( )", 100)
}else{
location.href=" redirect.php"
}
}
window.setTimeo ut('CountDown() ',100);
</script>
</HEAD>
<BODY>
<FORM NAME="form1">
You are being redirected in
<INPUT TYPE="text" NAME="clock" SIZE="5" VALUE="10">
seconds.
</FORM> 2 1782
libsfan01 wrote: 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:second s)? Which i feel is more aesthetically pleasing to the intended users of the site.
<script type="text/javascript">
var s = 15;
var href = 'http://localhost/';
var interval = null;
function display() {
var min = parseInt(s/60);
var sec = s - (60 * min);
document.getEle mentById('displ ay').innerHTML =
min + ' minutes, ' + sec + ' seconds';
}
function redirect() {
s--;
display();
if (!s) {
clearInterval(i nterval);
location = href;
}
}
window.onload = function () {
display();
interval = window.setInter val('redirect() ', 1000);
}
</script>
....
You are redirected in:
<span id="display">-- minutes, -- seconds</span>
JW
JRS: In article <11************ **********@z34g 2000cwc.googleg roups.com>
, dated Sat, 4 Mar 2006 04:52:36 remote, seen in
news:comp.lang. javascript, libsfan01 <ma********@msn .com> posted : 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:second s)? Which i feel is more aesthetically pleasing to the intended users of the site.
<HEAD> <SCRIPT LANGUAGE="JavaS cript">
Deprecated.
var start=new Date(); start=Date.pars e(start)/1000;
That first gets the date as an Object, then a String, them parses it to
its fields, then converts to Number.
var start = new Date()/1000 // or new Date().valueOf( )/1000
is simpler, though it does preserve the fractional part, which
Math.floor() or |0 will remove (|0 until 2038-01-19 03:14:08 UT IIRC).
var counts=100; //NUMBER OF SECONDS TO COUNTDOWN FROM function CountDown(){ var now=new Date(); now=Date.parse( now)/1000;
Ditto.
var x=parseInt(coun ts-(now-start),10);
That subtracts Numbers (which are integer value here), converts to
String, and converts back again. Omit use of parseInt.
if(document.for m1){document.fo rm1.clock.value = x;}
And what if not?
if(x>0){ timerID=setTime out("CountDown( )", 100) }else{ location.href=" redirect.php"
if (x<=0) location.href=" redirect.php"
should suffice.
Replace document.form1. clock.value = x
with s = x%60 ; m = (x-s)/60
document.form1. clock.value = m + (s>9?":":":0") + s
to get M:SS.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bob |
last post by:
Trying to convert timestamp data to date data (without the time in
hours/mins/secs), does only seem to work with TO_DATE(mydate; 'yyyymmdd').
But I do not want a string, but a real date like 29-03-2005.
How do I get it like that?
Thanks,
Bob
|
by: Bonnett |
last post by:
I have been creating a generic countdown timer (source code below), counting
the seconds, minutes, hours and days till an event, but I have having
trouble with it finding out how many hours are left. When i get it to
display a complete countdown (days hours mins seconds left) it is one hour
short when counting dates that fall in the following time brackets:
2004,2,29 -> 2004,9,31
2005,2,28 -> 2005,9,30
2006,2,27 -> 2006,9,29
etc..
|
by: lauren quantrell |
last post by:
I am using a timer to display the time it takes a user to complete a
file transfer using the code below.
The code below will display the total elapsed time, but is there a way
to update the time continuously as the file is being downloaded?
Help is greatly appreciated,
lq
Public sngStart as Single
Public sngEnd as Single
Public sngElapsed as Single
|
by: caulker |
last post by:
I have a simple Windows Service with a timer (system.timer).
The service seems to run just fine when I have the Timer = 1 minute, but
when I set the Timer = 15 minutes it only fires once ... then appears to
stop.
any help is greatly appreciated...
|
by: Noozer |
last post by:
I have a timer on a form. It isn't firing at all. I know that the timer is
enabled, and that the interval is low (4000, which should be 4 seconds). To
ensure the timer wasn't being inadvertantly reset I put some extra code in
the subs that enable and disable the timer. They fire as expected.
To test this I added a second timer with a 1 second interval. The event for
this time would output the enabled status of the first timer and its...
| |
by: Ben |
last post by:
I am trying to write codes in VB.net to display 3 images in series on a
Webform with each image being displayed in the same box for 5 seconds.
I am trying to use Timer and image button, don't know how to get around it.
thanks for any help
|
by: patelxxx |
last post by:
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
|
by: nadeemhannan |
last post by:
I need the code to write a timer, which will call webservice every 5 mins. and the web service function call will take two parameters: USERID and COMPUTER NAME/IP and will return true/false. If it returns true application can continue, otherwise display an error message and close Excel.
This code i will be implementing in excelVBA.
Thanks in advance
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |