-1

i want to create a timer for my php page i created the page that only 20 second i want that the time should be as 00:00:20 (hh:mm:ss) plz help my scipt are..........................................................................................................

<tr>
        <!-- countdown script --> 
            <td style="text-align:left;font-size:10pt;font-family:Verdana, Arial;">Time Left: <input type="text" name="seconds" size="3">
            <script language="javascript" type="text/javascript">
                var myTime = 20;
                function countDown() {
                    document.form.seconds.value = myTime;
                    if (myTime == 0) {
                        location.href="trivia1.php";
                    }
                    else if (myTime > 0) { 
                        myTime--;
                        setTimeout("countDown()",1000);
                    }
                }

                countDown();
            </script>
            </td>
</tr>

Edited by Nick Evan: Fixed formatting

Votes + Comments
Crossposting.
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by tiggsy
0

I'm not entirely sure what you mean, but if you want to measure the number of seconds between 2 events on a page in php, you'll have to load the page in between, because php is serverside, so it only fires once per page, basically.

I can see you're using javascript to try and do this. If you're measuring between page load time and something else, then I guess you could pick up the Universal Time (seconds since the epoch) at page load in php:

$start = date("U");

and pass it into javascript in your script with

<?php echo $start; ?>

then pick up the Universal time in javascript once the event has occurred and subtract start from it. You now have the number of seconds and you can display it any way you want.

Edited by tiggsy: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.