Results 1 to 2 of 2

Thread: Javascript/PHP Timer and Submit.... help please :)

  1. #1
    Join Date
    Aug 2006
    Posts
    7

    Javascript/PHP Timer and Script.... help please :)

    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

  2. #2
    Join Date
    Jun 2004
    Posts
    173
    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:

    Code:
    <!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>
    Last edited by Rambo Tribble; 05 Aug 2006 at 09:05 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •