Member
From: York, England
Registered: 2005-11-04
Posts: 605
I've been thanked 11 times.
Offline
Hello!
Ive got a PHP/MySql generated Number, lets say: 438
Id like to be able to get the number display to count up from zero and stop at 438, all in the browser display, quite quickly, infront of your very eyes!!
So i know it's gonna have to be javascript.
Ive googled this all morning and the best I can find are some Countdown/up timers. I know it's gonna be a pretty simple script for anyone who understands JS, but I don't, so Im knackered.
Could anyone point me in the right direction please?
Cheers
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2793
I've been thanked 77 times.
Offline
My JS is pretty poor as well, but here's my idea anyway-
eg 438 divs each with the number 1-438 in them
the js writes one at a time, applying styles to it as it goes
the positioning is the same each time but the visability of the previous one is set to 'hidden'
as this is done by a js function client side there will not be 438 divs visable in the code, but that's what the browser will display
I'm sure that there are more elegant solutions around. mobtex posted an ajax script that works, at times (broke my server the other night!).
There should be no need for divs, as you can use an input box for the same effect - just use CSS to remove the borders.
If that's what you need, then I already have a script that does that. All you'd need to do is adjust it so it gets the initial value from PHP.
Member
From: York, England
Registered: 2005-11-04
Posts: 605
I've been thanked 11 times.
Offline
oh, yes!
please may I have that script Tink!!
A few instructions would be good too!
Thanking you please
Check your PMs.
Member
From: South Africa, Port Elizabeth
Registered: 2006-08-23
Posts: 1896
I've been thanked 34 times.
Offline
forgive me if im wrong but surely this can be done by using a loop script in php... im not all that clued up on it either but i have been reading a few tutorials. Isnt it kind of like saying
"if this number(0) is equal to this number(438) stop
else +1"
and then just loop it.
And then use the print command to display each result as it occurs.
(number(438) would be a variable like "generated_number" obviously and would be pulled from the form that generates it)
At least thats how it would work in my head.... except with more squiggly bits etc
My up and coming... soon to be real website... www.thewebguy.co.za (one day i will finish it
)Member
From: York, England
Registered: 2005-11-04
Posts: 605
I've been thanked 11 times.
Offline
Tink sent me some JS to countdown to zero from the generated number. this was the code he sent me (thanks Tink)
Code: javascript
<script language="Javascript">
<!--Hide from old
var t = 30
function runTimer(){
document.set.timer.value = t
if(t >0 ) {
setTimeout("runTimer()", 1000)
}
if(t<=0){
document.set.timer.value = "0"
}
t--
}
//end hide-->
</script>
I had to create a form name "set" and an input field named "timer". the counter displayed inside there. 't' was where the variable went.
as I needed to count up, i (suprisingly) managed to alter it to this:
Code: javascript
<script language="Javascript" type="text/javascript">
<!--Hide from old
var t = 0
function runTimer(){
document.set.timer.value = t
if(t < ".$phpvariable.") {
setTimeout("runTimer()", 10)
}
if(t >=".$phpvariable."){
document.set.timer.value = "".$phpvariable.""
}
t++
}
//end hide-->
</script>
i then used CSS to format the input field, hidding the borders.
Oh, and I added the disabled attribute to the field to stop anyone typing into it.
It looks superb and Ive been accused of "just showing off now"
Many thanks for the help everyone.
Member
From: South Africa, Port Elizabeth
Registered: 2006-08-23
Posts: 1896
I've been thanked 34 times.
Offline
well, i wasnt exactly on key but damn i was close... with my theory i mean. I do believe i may be growing in this world of programming languages.... congrats griff, im glad it worked out for you 
My up and coming... soon to be real website... www.thewebguy.co.za (one day i will finish it
)| Never |


