I have an app that display’s the current time when a page opens. I would like that time to update every 30 seconds. I’ve read about prototype’s Ajax.PeriodicalUpdater and it seems to be an answer. This is how I achieve the static time display on page load with php:
<tr> <td> <input class='standard' type='text' name='start_time' value='<?php echo prev_end();?>'> <!--prev_end is last end time from database--> </td> <td> <input class='standard' type='text' name='end_time' value='<?php echo $now;?>'> <!--$now = date('G:i');--> </td>
This is what I’ve attempted with prototype:
<script type='javascript'> new Ajax.PeriodicalUpdater('updater', 'unow.php', {frequency : 30}); </script> ... <tr> <td> <input class='standard' type='text' name='start_time' value='<?php echo prev_end();?>'> </td> <td> <input id='updater' class='standard' type='text' name='end_time' value=''> </td>
Where ‘unow.php’ does this
<?php $unow=date('G:i'); echo $unow; ?>
It seems that I don’t need a callback to put the value from unow.php into the input ‘updater’ since PeriodicalUpdater calls for an element id. What am I missing?
Unless you want your time output to always match the timezone of the server, you could do this very quickly with a bit of Javascript on the client side and skip contacting the server entirely.