Consider this simple example;
<?php $text = test; ?>
<script type="text/javascript" defer="defer">
var test;
test = "<?php echo $text; ?>"
$(document).ready(function(){
alert(test);
});
</script>
This works fine. Creating the alert with the text from the php var. However, if I place;
<?php $text = test; ?>
below the script - it does not work. I've tried the defer function. What am I doing wrong?
Cheers
test
in PHP? – Felix Kling Jun 2 '11 at 12:12<?php $text = test; ?>
is wrong in any case unless you have a constanttest
. You should set a proper string:<?php $text = 'test'; ?>
. If you think you are referring to the JavaScript variabletest
if you put the line at the end, then you are wrong. See @Quentin's answer in this case. – Felix Kling Jun 2 '11 at 12:19