failbot8000
10-04-2012, 06:50 PM
Hello,
I am trying to write a javascript function to periodically update a div element. I want to use PHP to get the actual information. I know the periodic update works, but I can't get anything to display.
My code:
<script>
function updateDateTime()
{
<?php
ob_start();
$today = getdate();
echo $today[month] . ' ' . $today[mday] . ', ' . $today[year] . ' ' . ($today[hours] >= 12 ? $today[hours] - 12 : $today[hours]) . ':' . ($today[minutes] < 10 ? ('0' . $today[minutes]) : $today[minutes]) . ($today[hours] >= 12 ? 'pm' : 'am');
$string=ob_get_contents();
ob_end_clean();
print("var outputString = " . $string . " ;");
print("document.getElementById('datediv').innerHMTL=outputString;");
?>
}
var int=self.setInterval(function(){clock()},1000);
function clock()
{
updateDateTime();
}
</script>
Any ideas?
I am trying to write a javascript function to periodically update a div element. I want to use PHP to get the actual information. I know the periodic update works, but I can't get anything to display.
My code:
<script>
function updateDateTime()
{
<?php
ob_start();
$today = getdate();
echo $today[month] . ' ' . $today[mday] . ', ' . $today[year] . ' ' . ($today[hours] >= 12 ? $today[hours] - 12 : $today[hours]) . ':' . ($today[minutes] < 10 ? ('0' . $today[minutes]) : $today[minutes]) . ($today[hours] >= 12 ? 'pm' : 'am');
$string=ob_get_contents();
ob_end_clean();
print("var outputString = " . $string . " ;");
print("document.getElementById('datediv').innerHMTL=outputString;");
?>
}
var int=self.setInterval(function(){clock()},1000);
function clock()
{
updateDateTime();
}
</script>
Any ideas?