This command alone will do nothing:
javascript Code:
document.write("<?php echo 'hello!'; ?>");
But when combined with the script tags it will echo "Hello!'
providing you have PHP on the server you are using.
Javascript Code:
<script>
document.write("<?php echo 'hello!'; ?>");
</script>
Just as pressing a button in html will output a value from PHP using Javascript
providing you have PHP on the server you are using.
Example:
You can also use Javascript's Alert command to execute a PHP
function that has the database routine in it.
You can put any PHP code in a PHP function and let Javascript use it.
The only thing you have to remember is to echo something last that
the Alert command can use.
Here is a simple example that uses Javascript's Alert command to open
a file in write mode and write something to the file. Then echo a
message saying "Saving data to the file".
I think with a little practice you will find that you can get javascript
to have PHP do most anything you want it to do.: