Jump to content

Recommended Posts

riteo.

i have made a javascript countdown timer that resets after 5 minutes.

now there is a variable seconds for seconds and minutes for minutes which are originally and globally set.

the thing is that when u refresh the time goes back to the original time i want it to goto the countdown timers last time.

is there a way to do this in php ? or in javascript?
Link to comment
https://forums.phpfreaks.com/topic/9911-sharing-php-and-javascript-variables/
Share on other sites

thanx its like you cleaned my spark plugs and my brain can start again :P

should of thought of this earlier. thanx.

ill go see if i can do it

edit: ive managed to do the updating db but how would i go about making the javascript variable update to the new seconds variable when refreshed?

would i update the db to the time or a txt file or update some javascript variables?

how could i get the javascript variable into php?

if you cant understand me and u have msn add me: saiko@final-designs.com
You could try something like this

[code]<HTML>
<HEAD>
<script language="javascript">
    <?php
        $counter = isset($_GET['counter']) ? $_GET['counter'] : 300;
        echo "var counter = $counter";
    ?>

    function mycounter () {
        if (counter > 1)
            counter--;
        else
            counter = 300;
        
        // display counter    
        var obj = document.getElementById("counter");
        obj.innerHTML = counter;
        
        // store in hidden form field
        obj = document.getElementById("hidden");
        obj.value = counter;
        
        setTimeout("mycounter()", 1000);
    }
</script>
</HEAD>
<BODY onLoad = 'setTimeout("mycounter()", 0)'>

<SPAN id="counter" style="font-weight: 700; font-size: 24pt; color: red"></SPAN>

<FORM action="" method="GET">
        <input type="hidden" name="counter" id="hidden" value="0">
        <input type="submit" name="submit" value="Refresh page">
</FORM>
</BODY>
</HTML>[/code]
[!--quoteo(post=374894:date=May 18 2006, 10:30 AM:name=saiko)--][div class=\'quotetop\']QUOTE(saiko @ May 18 2006, 10:30 AM) [snapback]374894[/snapback][/div][div class=\'quotemain\'][!--quotec--]
the thing is that when u refresh the time goes back to the original time i want it to goto the countdown timers last time.

is there a way to do this in php ? or in javascript?
[/quote]

How, and how often, are you refreshing the page if not by user action?
yer i want it so when the user accesses the page it stores the variable to the hidden form etc.

then it updates the variable so then when the counter goes again it doesnt start from the original value.

or could i run the timer so it doenst have to do this.

this is for a game i am making.

my aim is for the timer to countdown to 0:00 then when it hits that it updates the databse and adds values like gold etc. then it resets to 5:00 and counts back down. i had that bit but when they accessed the page it went back to the original minute and second variable values.

so could i run this in another file or sumthin *confused*

note i have seen another site do this.

if u access it or refresh it, its timer will keep going or be like the rite time. so lets say u refresh and it takes to seconds then the timer will be eg. 14:14 then 14:12.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.