PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

Can I include Javascript in my PHP code?


Yes, you can use PHP straightforwardly to output JavaScript to the webpage.

Simply use the echo or print statement to do so, as you would with normal text or HTML that you are outputting to the screen.

Here's an example of this in action:

<?php 
echo "<script language=\"JavaScript\">"
echo 
"alert("PHP can write JavaScript you know!");"
echo 
"</script>"
?>



More other PHP Questions

How do I define a constant in PHP?
I have lots of if else logic - is there another option?
How do I check if a date entered exists?
How do I find out about my PHP installation?
How can I add branching logic to my PHP code?