saiko Posted May 18, 2006 Share Posted May 18, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/9911-sharing-php-and-javascript-variables/ Share on other sites More sharing options...
saiko Posted May 18, 2006 Author Share Posted May 18, 2006 i would also like to know how to update a database after that specific time.so if the countdown is from 5 minutes to 0 minutes then when it hits zero it updates the database and the timer resets. Quote Link to comment https://forums.phpfreaks.com/topic/9911-sharing-php-and-javascript-variables/#findComment-36847 Share on other sites More sharing options...
ober Posted May 18, 2006 Share Posted May 18, 2006 You can't do this strictly with JavaScript or PHP. You have to combine them with AJAX or you need to reload the page with the location JS call. Quote Link to comment https://forums.phpfreaks.com/topic/9911-sharing-php-and-javascript-variables/#findComment-36856 Share on other sites More sharing options...
saiko Posted May 19, 2006 Author Share Posted May 19, 2006 thanx its like you cleaned my spark plugs and my brain can start again :Pshould of thought of this earlier. thanx.ill go see if i can do itedit: 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 Quote Link to comment https://forums.phpfreaks.com/topic/9911-sharing-php-and-javascript-variables/#findComment-37103 Share on other sites More sharing options...
Barand Posted May 19, 2006 Share Posted May 19, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/9911-sharing-php-and-javascript-variables/#findComment-37112 Share on other sites More sharing options...
saiko Posted May 19, 2006 Author Share Posted May 19, 2006 thankyou im currently putting it into my script.but one thing is how would i make it so it does the updating of the counter variable without having to submit the form ? Quote Link to comment https://forums.phpfreaks.com/topic/9911-sharing-php-and-javascript-variables/#findComment-37117 Share on other sites More sharing options...
Barand Posted May 19, 2006 Share Posted May 19, 2006 [!--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? Quote Link to comment https://forums.phpfreaks.com/topic/9911-sharing-php-and-javascript-variables/#findComment-37120 Share on other sites More sharing options...
saiko Posted May 19, 2006 Author Share Posted May 19, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/9911-sharing-php-and-javascript-variables/#findComment-37122 Share on other sites More sharing options...
saiko Posted May 20, 2006 Author Share Posted May 20, 2006 *bump*ok another question.to update the database and add gold would i make a cron job or make a php script to do it.?if its a cron job can i please have some guidence Quote Link to comment https://forums.phpfreaks.com/topic/9911-sharing-php-and-javascript-variables/#findComment-37329 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.