DevHunters.com l Webmaster Forum - Web Advertising - Web Design - SEO Forums  

Go Back   DevHunters.com l Webmaster Forum - Web Advertising - Web Design - SEO Forums > Webmaster / Coding / Web Design Discussion > JavaScript Programming

JavaScript Programming Discuss javascript coding.

Have A Look At Some Of Our Webmaster Related Sponsors!


Social Groups


Script Directory


Shopping Cart


Free Templates

3D Guide-Characters
3D Guide-characters

social bookmarking network
Social Bookmarking

Reply
 
LinkBack Thread Tools Display Modes
Old 02-03-2008, 05:02 PM   #1 (permalink)
New Hunter
 

Join Date: Feb 2008
Posts: 10
iTrader: 0 / 0%
Hunter Bux: 10.00
watward07 is on a distinguished road
Default How do I make a counter that counts up?

It just has to count up, from 0, in seconds. That's all.
watward07 is offline   Reply With Quote
Old 02-03-2008, 05:32 PM   #2 (permalink)
The Dev Hunter
 
Hunter1's Avatar
 

Join Date: Mar 2007
Location: Indiana USA
Posts: 1,736
iTrader: 7 / 100%
Hunter Bux: 16,444.33
Blog Entries: 3
Hunter1 has much to be proud ofHunter1 has much to be proud ofHunter1 has much to be proud ofHunter1 has much to be proud ofHunter1 has much to be proud ofHunter1 has much to be proud ofHunter1 has much to be proud ofHunter1 has much to be proud of
Default

What will you be counting? What kind of site are you putting it in, PHP? HTML?
Hunter1 is online now   Reply With Quote
Old 02-03-2008, 11:18 PM   #3 (permalink)
Field Master
 
Neusha G.'s Avatar
 

Join Date: Oct 2007
Posts: 478
iTrader: 2 / 100%
Hunter Bux: 241.67
Neusha G. has a spectacular aura aboutNeusha G. has a spectacular aura aboutNeusha G. has a spectacular aura about
Default

I think he might want something that is like a stop watch maybe?
__________________
Cellular Ringtones
Neusha G. is offline   Reply With Quote
Old 02-04-2008, 08:17 PM   #4 (permalink)
Peter J. Foti
 
domainer50's Avatar
 
Join Date: Nov 2007
Location: Upstate NY
Posts: 322
iTrader: 0 / 0%
Hunter Bux: 0
domainer50 has a spectacular aura aboutdomainer50 has a spectacular aura aboutdomainer50 has a spectacular aura about
Send a message via AIM to domainer50 Send a message via MSN to domainer50 Send a message via Yahoo to domainer50
Default

Quote:
Originally Posted by Neusha G. View Post
I think he might want something that is like a stop watch maybe?
I think their are down loadable java scripts for things like this. My guess is that Google is your best friend in this situation.
__________________
PeterFoti.com
Register Domains
domainer50 is offline   Reply With Quote
Old 02-15-2008, 07:54 PM   #5 (permalink)
New Hunter
 

Join Date: Dec 2007
Location: United Kingdom - Dorset - Bournemouth
Posts: 85
iTrader: 0 / 0%
Hunter Bux: 5.00
Smiggy will become famous soon enoughSmiggy will become famous soon enough
Send a message via MSN to Smiggy
Default

Code:
<script>
x = 0;
function count()
{
	Object = document.getElementById('COUNT');
	Object.innerHTML = "<a onClick=\"count()\" id=\"COUNT\">" + x + "</a>";
	x = x + 1;
	setTimeout("count()",1000);
}
</script>

<a onClick="count()" id="COUNT">Click to begin Counter.</a>
__________________
<!-- I can type the entire Alphabet in 2.19 seconds -->

/* (X/D)Html, Css, Javascript, Ajax, Xml (DTD), PHP, MySQL, E4X */
/* Learning C++ and German */
Smiggy is offline   Reply With Quote
Old 02-15-2008, 09:53 PM   #6 (permalink)
Senior Moderator
 
SpOrTsDuDe.Reese's Avatar
Default

Quote:
Originally Posted by Smiggy View Post
Code:
<script>
x = 0;
function count()
{
	Object = document.getElementById('COUNT');
	Object.innerHTML = "<a onClick="count()" id="COUNT">" + x + "</a>";
	x = x + 1;
	setTimeout("count()",1000);
}
</script>

<a onClick="count()" id="COUNT">Click to begin Counter.</a>
Not valid of JavaScript is turned off. You should really look into php for counting visitors.
SpOrTsDuDe.Reese is online now   Reply With Quote
Old 02-15-2008, 10:19 PM   #7 (permalink)
Senior Moderator
 
weblord's Avatar
 

Join Date: Mar 2007
Location: Philippines
Posts: 1,373
iTrader: 1 / 100%
Hunter Bux: 611.00
weblord has much to be proud ofweblord has much to be proud ofweblord has much to be proud ofweblord has much to be proud ofweblord has much to be proud ofweblord has much to be proud ofweblord has much to be proud ofweblord has much to be proud of
Send a message via ICQ to weblord Send a message via AIM to weblord Send a message via MSN to weblord Send a message via Yahoo to weblord Send a message via Skype™ to weblord
Default

http://www.dynamicdrive.com/dynamici...countingup.htm

revised for your need

Code:
<html>
<head>
<style style="text/css">

.dcountstyle{ /*Example CSS to style count up output*/
font: bold 16px Arial;
padding: 3px;
}

.dcountstyle sup{ /*Example CSS to style count up output*/
font-size: 90%
}

</style>

<script type="text/javascript">

/***********************************************
* Dynamic CountUp script- ?? Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function dcountup(startingdate, baseunit){
this.currentTime=new Date()
this.startingdate=new Date(startingdate)
this.timesup=false
this.baseunit=baseunit
this.start()
}

dcountup.prototype.oncountup=function(){} //default action for "oncountup"

dcountup.prototype.start=function(){
var thisobj=this
this.currentTime.setSeconds(this.currentTime.getSeconds()+1)
var timediff=(this.currentTime-this.startingdate)/1000 //difference btw target date and current date, in seconds
var oneMinute=60 //minute unit in seconds
var oneHour=60*60 //hour unit in seconds
var oneDay=60*60*24 //day unit in seconds
var dayfield=Math.floor(timediff/oneDay)
var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))
if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
hourfield=dayfield*24+hourfield
dayfield="n/a"
}
else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
minutefield=dayfield*24*60+hourfield*60+minutefield
dayfield=hourfield="n/a"
}
else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
var secondfield=timediff
dayfield=hourfield=minutefield="n/a"
}
var result={days: dayfield, hours:hourfield, minutes:minutefield, seconds:secondfield}
this.oncountup(result)
setTimeout(function(){thisobj.start()}, 1000) //update results every second
}

</script>
</head>

<body>

<div id="cpcontainer">&nbsp;</div>

<script type="text/javascript">

//SYNTAX: myvariable=new dcountup(past_date_and_time_string, "baseunit")
var princewedding=new dcountup("April 9, 2005 13:30:00", "seconds")

princewedding.oncountup=function(result){
//result is an object containing the current count up date/time, updated every second
//Available properties: result["days"], result["hours"], result["minutes"], and result["seconds"]
var mycountainer=document.getElementById("cpcontainer")
mycountainer.innerHTML="Prince Charles and Camilla Parker have been married for: <br /><span class='dcountstyle'>"+result['seconds']+" <sup>seconds</sup></span>"
}

</script>

</body>

</html>
weblord is offline   Reply With Quote
Old 02-16-2008, 07:25 AM   #8 (permalink)
New Hunter
 

Join Date: Dec 2007
Location: United Kingdom - Dorset - Bournemouth
Posts: 85
iTrader: 0 / 0%
Hunter Bux: 5.00
Smiggy will become famous soon enoughSmiggy will become famous soon enough
Send a message via MSN to Smiggy
Default

PHP then - Unlike the JS one, this is not my script, can't remember where I got it from:
PHP Code:
<?php
file "counter.txt";
if (
file_exists($ file)) {
  $ 
fp fopen("$ file""r+");
  
flock($ fp1);
  $ 
count fgets($ fp4096);
  $ 
count += 1
  
fseek($ fp,0);
  
fputs($ fp, $ count);
  
flock($ fp3);
  
fclose($ fp);
  echo
"$ count";
} else {
  echo 
"Cannot open file - '$ file'<BR>";
}
?>
Just make an empty text fill named counter.txt and remove the spaces between the $ and the word. ;)
__________________
<!-- I can type the entire Alphabet in 2.19 seconds -->

/* (X/D)Html, Css, Javascript, Ajax, Xml (DTD), PHP, MySQL, E4X */
/* Learning C++ and German */

Last edited by Smiggy; 02-16-2008 at 07:31 AM.
Smiggy is offline   Reply With Quote
Old 02-16-2008, 07:28 AM   #9 (permalink)
New Hunter
 

Join Date: Dec 2007
Location: United Kingdom - Dorset - Bournemouth
Posts: 85
iTrader: 0 / 0%
Hunter Bux: 5.00
Smiggy will become famous soon enoughSmiggy will become famous soon enough
Send a message via MSN to Smiggy
Default

Why wont it show you the $ thingys when you put them together??
__________________
<!-- I can type the entire Alphabet in 2.19 seconds -->

/* (X/D)Html, Css, Javascript, Ajax, Xml (DTD), PHP, MySQL, E4X */
/* Learning C++ and German */

Last edited by Smiggy; 02-16-2008 at 07:32 AM.
Smiggy is offline   Reply With Quote
Old 02-16-2008, 12:26 PM   #10 (permalink)
Senior Moderator
 
SpOrTsDuDe.Reese's Avatar
Default

What are you talking about.
__________________
+-(X)HTML, CSS, JavaScript, SEO, PHP, Flash-+
Code:
<style type="text/css"> u { text-decoration: none; } </style>
SpOrTsDuDe.Reese is online now   Reply With Quote
Old 02-16-2008, 04:49 PM   #11 (permalink)
New Hunter
 

Join Date: Dec 2007
Location: United Kingdom - Dorset - Bournemouth
Posts: 85
iTrader: 0 / 0%
Hunter Bux: 5.00
Smiggy will become famous soon enoughSmiggy will become famous soon enough
Send a message via MSN to Smiggy
Default

If you look at the PHP counter coding I did, I had to make a space in between the $ and the word otherwise it would disapear...Why???
__________________
<!-- I can type the entire Alphabet in 2.19 seconds -->

/* (X/D)Html, Css, Javascript, Ajax, Xml (DTD), PHP, MySQL, E4X */
/* Learning C++ and German */
Smiggy is offline   Reply With Quote
Old 02-16-2008, 07:15 PM   #12 (permalink)
Field Master
 
karthikeyan's Avatar
 

Join Date: Jun 2007
Posts: 611
iTrader: 0 / 0%
Hunter Bux: 509.00
karthikeyan is on a distinguished road
Send a message via MSN to karthikeyan Send a message via Yahoo to karthikeyan
Default

Quote:
Originally Posted by Smiggy View Post
PHP then - Unlike the JS one, this is not my script, can't remember where I got it from:
PHP Code:
<?php
file "counter.txt";
if (
file_exists($ file)) {
  $ 
fp fopen("$ file""r+");
  
flock($ fp1);
  $ 
count fgets($ fp4096);
  $ 
count += 1
  
fseek($ fp,0);
  
fputs($ fp, $ count);
  
flock($ fp3);
  
fclose($ fp);
  echo
"$ count";
} else {
  echo 
"Cannot open file - '$ file'<BR>";
}
?>
Just make an empty text fill named counter.txt and remove the spaces between the $ and the word. ;)
Thanks For the script!
__________________
My Tech Blog
karthikeyan is offline   Reply With Quote
Old 02-16-2008, 07:25 PM   #13 (permalink)
New Hunter
 

Join Date: Dec 2007
Location: United Kingdom - Dorset - Bournemouth
Posts: 85
iTrader: 0 / 0%
Hunter Bux: 5.00
Smiggy will become famous soon enoughSmiggy will become famous soon enough
Send a message via MSN to Smiggy
Default

No Problem.
__________________
<!-- I can type the entire Alphabet in 2.19 seconds -->

/* (X/D)Html, Css, Javascript, Ajax, Xml (DTD), PHP, MySQL, E4X */
/* Learning C++ and German */
Smiggy is offline   Reply With Quote
Old 03-08-2008, 11:21 AM   #14 (permalink)
New Hunter
 

Join Date: Mar 2008
Posts: 9
iTrader: 0 / 0%
Hunter Bux: 10.00
Tequila is on a distinguished road
Default

thanks for the script
Tequila is offline   Reply With Quote
Old 04-10-2008, 10:49 PM   #15 (permalink)
New Hunter
 

Join Date: Apr 2008
Posts: 8
iTrader: 0 / 0%
Hunter Bux: 0
jani is on a distinguished road
Send a message via Yahoo to jani
Default visit this site

Free Hit Counters with or without Statistics - track everything about your visitors with our free hit counter.

visit this sites i found the best site................

enjoy it
jani is offline   Reply With Quote
Old 04-11-2008, 06:08 AM   #16 (permalink)
Senior Moderator
 
SpOrTsDuDe.Reese's Avatar
Default

Quote:
Originally Posted by Smiggy View Post
If you look at the PHP counter coding I did, I had to make a space in between the $ and the word otherwise it would disapear...Why???

echo"$ count";

If you mean that, you can get rid of the space between it. If you don't mean that, specify which line you are talking about so I can parse it correctly :D. It shouldn't be a variable if you have a space.

EDIT: Looking at the code, the variable was defined this way

$ count

So if you want to call it, you must put a space. Hope that helped.
__________________
+-(X)HTML, CSS, JavaScript, SEO, PHP, Flash-+
Code:
<style type="text/css"> u { text-decoration: none; } </style>

Last edited by SpOrTsDuDe.Reese; 04-11-2008 at 06:10 AM. Reason: Noticed the variable thing
SpOrTsDuDe.Reese is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:34 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0