I have a problem with PHP and Javascript variable communication. I have this code:
<?php
$php_var = 'lol';
?>
<html>
<script type="text/javascript" charset="utf-8">
var php_var = "<?php echo $php_var; ?>";
alert(php_var);
</script>
</html>
This code does not work (as intended) for some reason. I cannot get the PHP variable's value passed down to Javascript variable. For some reason, Javascript completely ignores the php tags and assigns php_var a value of "". So it alerts the literal php code I put it as.
What am I doing wrong? I have been stuck on this problem for 3 hours. Is it my server's problem? (Using web hosting, dedicated). Thank you
.php
extension correct? – JaredMcAteer Jul 24 '12 at 19:04lol
in it in both FireFox and IE. – newfurniturey Jul 24 '12 at 19:06