Reputation: 844
Take in mind the following; the code below and programs associated at it is runs perfectly.
<script>
window.vorderby = "YEAR"
exibelivrosAJAX();
</script>
but, when I did the modify below gave me the following error: Uncaught ReferenceError: YEAR is not defined
<script>
window.vorderby = <?php echo $_POST['formorderby']; ?>;
exibelivrosAJAX();
</script>
Looking for and reading tons of messages I did the following:
<script type="text/javascript" src="funcoesJS.js">
window.vorderby = <?php echo $_POST['formorderby']; ?>;
exibelivrosAJAX();
</script>
and the error was solved. But, the function exibelivrosAJAX() don't run.
Below you can see the two pieces of code that I think can help you to understand a little better.
1st piece of code in the primary file: echo " ";
2nd piece of code in another php file: window.vorderby = ; exibelivrosAJAX();
Could you help me to understand it? Thanks a lot! Marcos.
Upvotes: 0
Views: 50
Reputation: 22817
You still need the JS quotes:
<script>
window.vorderby = "<?php echo $_POST['formorderby']; ?>";
exibelivrosAJAX();
</script>
In the 2nd example, your code is not executed [and therefore you get no error] because of the src
attribute of the script
tag.
Upvotes: 2
Reputation: 10148
You forgot to enclose the outputed variable with qoutes
window.vorderby = "<?php echo $_POST['formorderby']; ?>";
Upvotes: 1