I'm using javascript to create timers that will start a count down after the page is loaded. I need to do the calculation of seconds for the timers in php on the page that calls this page with the javascript. I then pass the seconds when I write the javascript using php. Here I'm just showing the javascript with the seconds hard-coded for each timer. I've tried testing this as is (with the javascript hard-coded just as shown here), but all it will do is display the starting point for each timer but won't advance beyond that. It is supposed to show the timers counting down each second.
I need to do the calculation of seconds for the timers in php on the page that calls this page with the javascript. I then pass the seconds when I write the javascript using php.
Ha? How's that? Sounds confusing. Do you?:
- have a time variable written with php in document A,
- open with javascript the document B
- pass that variable time from document A to document B
- use that variable as a start time for a JavaScript counter
- pass back this variable to the document A (when?)
I will try what Rufe0 suggested later today, but here is what you were asking about Kor:
first, to make it clear, doc A has the php server logic and doc B renders the html and js. doc b is an include file in doc a.
Do I:
- have a time variable written with php in document A,
-> yes, that is the number of seconds
- open with javascript the document B
-> doc B is a php doc where I write the js dynamically so that I can fill in the seconds from doc A
- pass that variable time from document A to document B
-> the prior answer is how I pass the seconds from doc A to Doc B
- use that variable as a start time for a JavaScript counter
-> where you see the hard-coded seconds in the function (120, 60, 30) is where I will write the three different variables from doc A. I have only hard-coded them here to get this script working.
- pass back this variable to the document A (when?)
-> I do not pass the variable back to doc A. the js keeps counting down the timers in doc B. I use a meta tag in doc B to refresh every 60 seconds. When that happens, doc a reruns the logic to calculate the three variables holding the seconds and that is used to reset the timer display and countdowns on doc b. Remember that I need to rely solely on the clock on the server (which is where doc a pulls its times to do the seconds calculations until the next event).
Bookmarks