Forum Moderators: open

Message Too Old, No Replies

PHP and Javascript

         

Gian04

10:47 am on Jun 3, 2009 (gmt 0)

10+ Year Member



I have a php code that retrieve the server date/time. Retrieved date/time will be saved to a variable.

Then I have a javascript that displays a running clock on my page.

Question: How can I pass the variable value (from PHP) to my Javascript so that the variable value will be the initial value for my javascript?

whoisgregg

7:20 pm on Jun 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can echo php code into a javascript directly:

<script type="text/javascript">
var startTime = '<?php echo date("Y-m-d H:i:s"); ?>';
alert(startTime); // for testing only
</script>