0

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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

You forgot to enclose the outputed variable with qoutes

window.vorderby = "<?php echo $_POST['formorderby']; ?>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.