HTML/PHP:
<button onclick="change_value(<?php echo $date?>)">Go</button>
JavaScript:
function change_value(date_used)
{
alert(date_used);
}
When I right-click on the button and click the "Inspect Element" button shows the parameter correctly, i.e something like this:
<button onclick="change_value(2012-08-22)">Go</button>
But the alert in the JavaScript is displaying 1981. That's it - only 1981. Not only the date is wrong, but the format, too.
What is this happening and how can I fix it?
2012 - 08 - 22) instead of a string ("2012-08-22") intochange_value. It's like asking "Why doesprint(3-2);output1?". Usechange_value(<?php echo json_encode($date); ?>)instead.2012-08-22 = 2012 - 1 - 22 = 1981. Your dat is interpreted as a numeric operation and08is interpreted as an octal number (08 = 1 in octal)