PHP executes at runtime, your code creates something like this:
function handleEvent(e){
if(e.keyCode === 13){
hello
}
}
echo is a php function which simple prints eveything inside “” into the markup. So just print with php what you else would write by hand:
function handleEvent(e){
if(e.keyCode === 13){
<?php
echo "alert(\"hello\");";
?>
}
}
echo "alert(\"hello\");"; tells php to print alert("hello");. The \" makes sure echo prints the " character itself (because the string that echo needs to print is also written in ", so you need to escape additional ones, alternatively write echo 'alert("hello");';)
2
solved PHP echo in javascript not displayed in browser [duplicate]