PDA

View Full Version : Javascript/PHP Timer and Submit.... help please :)



Submerged
01 Aug 2006, 03:31 AM
Hi, my name is Alex, I'm new here... I'm working on a site, but there is one script that I have no clue how to do. I mostly work with PHP, Javascipt is pretty alien to me.

Basically, when the scripts loads, I need to display a timer that counts down from 20. Then, when it hits 0, I need to run a little PHP script to display some random numbers (the script to write the numbers I can handle, I just need the script to be triggered after the timer runs out). It would be awesome if, when the timer hit 0, the timer disappeared, so the n umbers would appear in it's place, but ill be fine without it.

I dont know how tough that is, but if someone could help me a bit with the script I would be very grateful :)

Thanks for your time,
-Alex (Submerged)

PS. If you are wondering why it mentioned a Submit in the title, it's because I changed the idea well I was writing the post to make it simpler, but forgot to edit the title. No submit button is actually needed ;)

Rambo Tribble
04 Aug 2006, 11:40 PM
If you want to keep the page the same and update it with the PHP numbers, you'll need to use AJAX. The timer is fairly simple. Here's one approach:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css">
</style>
<script type="text/javascript">
var cnt=19;
function cntDwn(){
if(cnt>=0){
tmr=setTimeout('dispTime()',1000);
}else{
//do submit code
alert('this is it');
}
}
function dispTime(){
targ.innerHTML=cnt;
cnt--;
cntDwn();
}
window.onload=function(){
targ=document.getElementById('divOne');
cntDwn();
}
</script>
</head>
<body>
<div id="divOne" style="font:3em Verdana;width:2em;text-align:right;">20</div>
</body>
</html>