TripleDES Posted June 28, 2008 Share Posted June 28, 2008 If I store a variable in $date= $_POST['date']; How do I go about using it in a javascript? { var myAjax = new Ajax.PeriodicalUpdater('date', 'rand.php', {method: 'post', frequency: 5.0, decay: 1}); } Link to comment https://forums.phpfreaks.com/topic/112324-using-a-php-variable-in-javascript/ Share on other sites More sharing options...
DJTim666 Posted June 28, 2008 Share Posted June 28, 2008 You can use; <?=$date?> or; <?php echo $date; ?> -- DJ Link to comment https://forums.phpfreaks.com/topic/112324-using-a-php-variable-in-javascript/#findComment-576714 Share on other sites More sharing options...
TripleDES Posted June 28, 2008 Author Share Posted June 28, 2008 Thanks, but I still can't get it to work: { var myAjax = new Ajax.PeriodicalUpdater('date', <?=$date?>, {method: 'post', frequency: 5.0, decay: 1}); } Link to comment https://forums.phpfreaks.com/topic/112324-using-a-php-variable-in-javascript/#findComment-576805 Share on other sites More sharing options...
TripleDES Posted June 28, 2008 Author Share Posted June 28, 2008 Simple example: <script> var test = "<?php echo date.php;?>"; function myDate() { var myAjax = new Ajax.PeriodicalUpdater('date', test, {method: 'get', frequency: 2.0, decay: 1}); } </script> Link to comment https://forums.phpfreaks.com/topic/112324-using-a-php-variable-in-javascript/#findComment-576806 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.