0
How to add php code in a javascript function?
2 Answers
+ 2
It's not possible.
JavaScript is a client-side language. PHP is a server-side language. For security reasons among others, JavaScript cannot use PHP.
However, as a substitute, you can call another page that uses PHP.
@Kamil, the PHP part is automatically removed when ran and then you're just left with the string. No real PHP operations can be performed with that method.
+ 2
you could write this js code: document.write ("
<?php
echo "text";
?>
") this will execute the php code via js
of course this won't work if you are not on a server with php installed