javascript - Uncaught reference error for echo function in php -


i have used follwoing php code snippet inside java script code(inside parent html).

<script>     function setoptions(d) {         <?php             echo "test";         ?>     } </script> 

when content saved , web page refreshed, following error,

uncaught referenceerror: test not defined

note- echo works when directly used inside html code.

any idea on how fix problem?

what want happen? when code parsed php sends browser (not valid javascript in function):

<script>     function setoptions(d) { test     } </script> 

so produced needs valid javascript this:

<script>     function setoptions(d) {         <?php             echo 'alert("test");';         ?>     } </script> 

would produce valid javascript:

<script>     function setoptions(d) { alert("test");     } </script> 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -