I have a php date and wish to echo it out in a javascript alert box:-
$day=15;
$month=8;
$year=2012;
$date_display = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));
echo $date_display; // 2012-08-15
Then,
<a href="#" onclick="give_date(<?=$date_display;?>)"><?=$day;?></a>
The javascript function:
<script>
function give_date(value){
alert (value);
}
</script>
Interestingly, the alert box give me "1989", which equals to 2012 minus 8 minus 15!! what shall I do!!
Now you get: <a href="#" onclick="give_date(2012-08-15)">15</a>, so it calculates it in browser.
the solution is simple - add quotes:
<a href="#" onclick="give_date('<?=$date_display;?>')"><?=$day;?></a>
Then you get: <a href="#" onclick="give_date('2012-08-15')">15</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With