...

View Full Version : any ideas?



monsta1
02-01-2007, 04:50 PM
Would it be possible to incorporate a “counter” that changes every 2 seconds i.e. “X” promotional brochures circulated so far this year? This year “X” would be 1 brochure per 2 seconds (30 per minute) i.e. by end of January 31st value of “X” would be 31x24x60x30=1,339,200. At end of 2007 = 365x24x60x30=15,768,000.

I need it so that it will continue to count when viewed by different users( like a web counter)

Many thanks

glenngv
02-01-2007, 05:52 PM
<html>
<head>
<script type="text/javascript">
var fromDate = new Date(new Date().getFullYear(), 0, 1);
function setCtr(){
var toDate = new Date();
var diff = (toDate - fromDate)/1000; //sec
document.getElementById("ctr").innerHTML = Math.round(diff/2);
}
</script>
</head>
<body onload="setInterval('setCtr()', 2000);">
<div>Number of promotional brochures circulated so far this year: <span id="ctr"></span></div>
</body>
</html>
If you want to put commas to the number, you can search for such kind of script here in CF, try looking in the Post a Javascript forum.

monsta1
02-02-2007, 06:42 PM
Hi Glenn.
Many thanks for the coding, just have a few questions though.
Can I just cut and paste this in or do I have to add any dates in to it?
Could I start it running from 4th of Feb and add the starting amount to it?

Many thanks
Keith

tonyp12
02-02-2007, 07:24 PM
to start from 7am

var fromDate = Date.parse("Feb 4, 2007, 07:00:00")
--
var diff = (toDate.getTime() - fromDate)/1000; //sec
--
document.getElementById("ctr").innerHTML = Math.round(diff/2)+ how many already done before Feb4

tonyp12
02-02-2007, 09:09 PM
To get two: , to show thousands & millions.
(any count before feb4 should be added after '/2000 + number' )

var fromDate = Date.parse("Feb 4, 2007, 07:00:00");
function setCtr(){
var toDate = new Date();
var mycount = Math.round((toDate.getTime() - fromDate)/2000).toString();
var mylen = mycount.length;
if (mylen>3){mycount= mycount.slice(0,mylen-3) + "," + mycount.slice(mylen-3)}
if (mylen>6){mycount= mycount.slice(0,mylen-6) + "," + mycount.slice(mylen-6)}
document.getElementById("ctr").innerHTML = mycount;
}

monsta1
02-03-2007, 11:18 PM
Hi Tony,
I uploaded this to my site and it was befor the start date, but nothing happened. Have I done something wrong?

</head>
<body onload="setInterval('setCtr()', 2000);">
<html>
<head>
<script type="text/javascript">var fromDate = Date.parse("Feb 3, 2007, 22:08:00");
function setCtr(){
var toDate = new Date();
var mycount = Math.round((toDate.getTime() - fromDate)/2000
+ 1999 ).toString();
var mylen = mycount.length;
if (mylen>3){mycount= mycount.slice(0,mylen-3) + "," + mycount.slice(mylen-3)}
if (mylen>6){mycount= mycount.slice(0,mylen-6) + "," + mycount.slice(mylen-6)}
document.getElementById("ctr").innerHTML = mycount;
}
</script>
</head>

tonyp12
02-03-2007, 11:37 PM
You have two sets of <head></head> ?

Here it's (http://home.comcast.net/~tony1717/test.html) running just fine.

<html>
<head>
<title>mycounter</title>
<script type="text/javascript">

put JS code here

</script>
</head>
<body onload="setInterval('setCtr()', 2000);">

put your html here

</body>
</html>

I have edited so if production date is in the future is will only show 1,999 (that's the units that is ready as of now)

monsta1
02-03-2007, 11:48 PM
Hi Tony
This is what is pasted in.

<html>
<head>
<script type="text/javascript">var fromDate = Date.parse("Feb 3, 2007, 22:08:00");
function setCtr(){
var toDate = new Date();
var mycount = Math.round((toDate.getTime() - fromDate)/2000
+ 1999 ).toString();
var mylen = mycount.length;
if (mylen>3){mycount= mycount.slice(0,mylen-3) + "," + mycount.slice(mylen-3)}
if (mylen>6){mycount= mycount.slice(0,mylen-6) + "," + mycount.slice(mylen-6)}
document.getElementById("ctr").innerHTML = mycount;
}
</script>
</head>
<body onload="setInterval('setCtr()', 2000);">
<div>Number of promotional brochures circulated so far this year: <span id="ctr"></span></div>
</body>

tonyp12
02-04-2007, 12:19 AM
And does it work?

click Here (http://home.comcast.net/~tony1717/test.html)
then Right click on that webpage and select 'viewsource'

So at 10:08pm tonight you start with 1999 units and add one every 2 second after that?

tonyp12
02-04-2007, 01:03 AM
Updated version that does not show negative amount, in case the fromDate is in the future.
1,999 is what is already done, note it twice and once with " "


<html>
<head>
<title>mycounter</title>
<script type="text/javascript">

var fromDate = Date.parse("Feb 3, 2007, 22:08:00");
function setCtr(){
var toDate = new Date();
var mycount = Math.round((toDate.getTime() - fromDate)/2000)
mycount = mycount>0 ? (mycount + 1999).toString() : "1999"

var mylen = mycount.length;
if (mylen>3){mycount= mycount.slice(0,mylen-3) + "," + mycount.slice(mylen-3)}
if (mylen>6){mycount= mycount.slice(0,mylen-6) + "," + mycount.slice(mylen-6)}
document.getElementById("ctr").innerHTML = mycount;
}


</script>
</head>
<body onload="setInterval('setCtr()', 2000);">

<div>Number of promotional brochures circulated so far: <span id="ctr"></span></div>

</body>
</html>

monsta1
02-04-2007, 05:40 PM
Hi tony,
Tried it by adding into my homepage and uploading it. Still did not work. Click here (http://www.everything-advertising.co.uk) to have a look.
set it for 4.30pm today
Many thanks
Keith

tonyp12
02-04-2007, 05:44 PM
You can not simple use cookie cutter to paste any example from this board.
You have to merge the 3 important part to your specific website.


You arlready have <script></script>
Put the JS code in between



function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var fromDate = Date.parse("Feb 4, 2007, 16:30:00");
function setCtr(){
var toDate = new Date();
var mycount = Math.round((toDate.getTime() - fromDate)/2000)
mycount = mycount>0 ? (mycount + 1999).toString() : "1999"

var mylen = mycount.length;
if (mylen>3){mycount= mycount.slice(0,mylen-3) + "," + mycount.slice(mylen-3)}
if (mylen>6){mycount= mycount.slice(0,mylen-6) + "," + mycount.slice(mylen-6)}
document.getElementById("ctr").innerHTML = mycount;
}

//-->
</script>
</head>
<body leftmargin=0 rightmargin=0 topmargin=0 bottommargin=0 onLoad="MM_preloadImages('images/about_us_03.jpg','images/system_03.jpg','images/modules_03.jpg.jpg','images/demo_03.jpg','images/services_03.jpg','images/partner_03.jpg','images/contacts_03.jpg')">
<div align="center">


And DELETE all this, leave what is in red text.

<html>
<html>
</body>
</html></body>
</html></html><html><body><p>
&nbsp;<html>
<head>
<title>mycounter</title>
<script type="text/javascript">

var fromDate = Date.parse("Feb 4, 2007, 16:30:00");
function setCtr(){
var toDate = new Date();
var mycount = Math.round((toDate.getTime() - fromDate)/2000)
mycount = mycount>0 ? (mycount + 1999).toString() : "1999"

var mylen = mycount.length;
if (mylen>3){mycount= mycount.slice(0,mylen-3) + "," + mycount.slice(mylen-3)}
if (mylen>6){mycount= mycount.slice(0,mylen-6) + "," + mycount.slice(mylen-6)}
document.getElementById("ctr").innerHTML = mycount;
}


</script>
</head>
<body onload="setInterval('setCtr()', 2000);">

<div>Number of promotional
<br>brochures circulated so far: <span id="ctr"></span></div>
</body>
</html></p>
</body>
</html>

Add the red text to your onLoad.
<body leftmargin=0 rightmargin=0 topmargin=0 bottommargin=0 onLoad="setInterval('setCtr()', 2000); MM_preloadImages('images/about_us_03.jpg',...............

This is the edited version of your website:
BrochureConnect.html (http://home.comcast.net/~tony1717/BrochureConnect.html)
It will not show visually correctly as I don't have the pictures/fonts (but will on your server)

I see that you have some unused CSS, replace #counter to #ctr if you want a different look to the numbers.

<style type="text/css">
#counter{
font-weight:bold;
color:highlight;
}

monsta1
02-04-2007, 10:05 PM
Hi Tony, You are a star. I have no idea on these type of things, trying to learn though. What do I need to do to get the number to appear in bold?

Many thanks again.
Keith:thumbsup:

tonyp12
02-04-2007, 10:39 PM
To get bold, change the top of your html.


<html>
<head>
<title>mycounter</title>
<meta http-equiv="Content-Language" content="en-gb">
<title>-</title>
<style type="text/css">
#ctr{
font-weight:bold;
color:highlight;
}
</style>
<META NAME="robots" CONTENT="all">
<META NAME="title" CONTENT="Brochureconnect: Literature display and distribution services. Brochure display stands and leaflet displays.">
<META NAME="description" CONTENT=""Use Brochureconnect to distribute and display literature, leaflets, brochures and tourist information, displayed using our own or your branded, brochure display stands. ">
<META NAME="keywords" CONTENT="brochureco

And delete this erronous text in red at bottom.


<p>Brochure</font><font FACE="Tahoma" COLOR="#008000">Connect</font></b><font FACE="Tahoma">
<b>is dedicated to bringing you just this.</b></p>
</font><font SIZE="2" COLOR="#008000" face="Tahoma">
<p><b>We work hard to ensure your print is seen in your marketplace
and produces optimum results for you.</b><html><body onload="setInterval('setCtr()', 2000);"><div>&nbsp;<span id="ctr"></span></div>
</body>
</html></font></td>
</tr>
</table>

monsta1
02-06-2007, 11:56 PM
Many thanks Tony.

Keith



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum