I'm a bit confuse on passing PHP variables that contains date on an onclick attribute of a button, for example.. (for some reason, I put the button inside an echo)
<?php
$date = date("F-d-Y", "2015-07-24"); //to convert the string 2015-07-24 to date with an specific format
echo "<button onclick = 'goToThisJSMethod(".$date.")'> Pass </button>";
?>
on the javascript part wherein goToThisJSMethod written.
function goToThisJSMethod(dateRec){
alert (dateRec);
}
The syntax above results nothing and the alert box didn't appear
I tried changing the above code, I alter the parameter that will be passed on PHP, instead of using $date variable, I used the exact string of the date to be the parameter and change the javascript like this:
function goToThisJSMethod(dateRec){
var date = new Date(dateRec);
alert(date.getMonth()+1 " " + date.getDate() + " " + date.getFullYear());
}
Yes there's a result with this but then again, it returns a default date of 1/1/1970. What should I do regarding with this problem?