update JS Var on chaging of a php var

gerardosepia

New Member
I got this prob. In a web page I have a DIV that display a counter ( a PHP variable, $count). I have also a JS function that change the INNERHTML property of the DIV. I'm not able to change the js var on the changing of the PHP one.HTML\[code\]<DIV id="counter">0</DIV>\[/code\]PHP\[code\]while (----) { do_something; $count++;}\[/code\]JS\[code\]function ChangeDiv() {document.getElementById("counter").innerHTML = // here the value of $count;}setinterval("ChangeDiv()",3600);\[/code\]I want to to refresh the DIV every sec inserting in it the value of $count... but doing\[code\]document.getElementById("counter").innerHTML = <?php echo($count); ?>;\[/code\]is wrong 'cause it will output just the initial value of $count.I tried to insert a parameter in the function ChangeDiv, but in that way I had to call the function every time $count changed, echoing a \[code\]echo("<script>ChangeDiv('".$count."');</script>");\[/code\]...that's really not functional.Someone knows a simpler way to do it??
 
Back
Top