![]() |
|
|||||||
| JavaScript Programming Discuss javascript coding. |
This is a discussion on Count up counter in javascript within the JavaScript Programming forums, part of the Webmaster / Coding / Web Design Discussion category; Hi All, I have to built a counter (count will start from 1 and will increment to 1 every second) ...
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 |
|
New Hunter
|
Hi All,
I have to built a counter (count will start from 1 and will increment to 1 every second) which will start or paused on click of button. Can anybody give some idea on how to proceed for this. Regards, Kaushal |
|
|
|
|
|
#2 |
|
Senior Hunter
|
Hmm, would you like us to use our knowledge of us reading your mind? How are we supposed to know without code o.O. A website would be preferable.
__________________
Looking for HTML/CSS work. If interested in hiring, please Use my site /* CSS guru */ |
|
|
|
|
|
#3 | |
|
New Hunter
|
Quote:
Code:
<html>
<head>
<title>CountUp Script</title>
<script type="text/javascript">
function showElapsedTime()
{
// Description:
// This is a countup script from a specific date in the past.
// It shows the days, hours, minutes and seconds that have elapsed since the start date.
// For added effect, the elapsed time is updated each second.
//
// Set the starting date details.
var startYear = 2007;
var startMonth = 11; // must be between 0 - 11
var startDay = 21; // must be between 1 - 31
var startHour = 0; // must be between 0 - 23
var startMinute = 0; // must be between 0 - 59
var startSecond = 0; // must be between 0 - 59
var startDate = new Date();
startDate.setYear(startYear);
startDate.setMonth(startMonth);
startDate.setDate(startDay);
startDate.setHours(startHour);
startDate.setMinutes(startMinute);
startDate.setSeconds(startSecond);
var rightNow = new Date();
var elapsedTime = rightNow.getTime() - startDate.getTime();
var one_day=1000*60*60*24;
var elapsedDays = Math.floor( elapsedTime / one_day );
var milliSecondsRemaining = elapsedTime % one_day;
var one_hour = 1000*60*60;
var elapsedHours = Math.floor(milliSecondsRemaining / one_hour );
milliSecondsRemaining = milliSecondsRemaining % one_hour;
var one_minute = 1000*60;
var elapsedMinutes = Math.floor(milliSecondsRemaining / one_minute );
milliSecondsRemaining = milliSecondsRemaining % one_minute;
var one_second = 1000;
var elapsedSeconds = Math.round(milliSecondsRemaining / one_second);
document.getElementById('elapsedTime').innerHTML = elapsedDays + " Days " + elapsedHours + " Hours " + elapsedMinutes + " Minutes " + elapsedSeconds + " Seconds";
t = setTimeout('showElapsedTime()',1000);
}
</script>
</head>
<body onload="showElapsedTime()">
<div id="elapsedTime"></div>
</body>
</html>
|
|
|
|
|
|
|
#4 |
|
New Hunter
|
To protect your computer, it is vital that you use a powerful antivirus and antispyware scanner like www.search-and-destroy. Free update antivirus definitions daily, scan your computer once a day for infections and keep all of your software patched and up-to-date.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|