Possible Duplicate:
how to put javascript variable in php echo
I have JavaScript to get time and the code is below.
<script type="text/javascript">
var d = new Date();
var H = d.getHours();
var m = d.getMinutes();
if(H>11)
{
var h = H-12;
var a = 'PM';
}
else
{
var h = H;
var a = 'AM';
}
</script>
Now, I want to print the variables in PHP that used in JavaScript like,
<?php echo $h.$m; ?>
Is it possible?
if yes then help me.
Javascipt runs on the client, php runs on the server... If you just want to print the var in the browser
var varName = "varValue";
document.write(varName);
if you need to send the javascript var to php, you need to send it to the server with jquery or javscript and then return the data...
$.post("yourFile.php", { varName: "varValue" },
function(data) {
//print the data coming from yourFile.php
document.write(data);
});
if you only need to send the var to the server
$.post("yourFile.php", { hour: "hour", min: "min", sec:"sec" } );