How to echo() javascript alert();?

Hi, what I want is to execute some javascript code with echo(); basicallly see below what I want

echo "<script>javascript: alert('test msgbox')></script>";

the above code doesnt work, how to evaluate javascript code in echo() ?

please help…

thanks

I also tried the script type…

<script type=“text/javascript”>

but it does not execure my javascript functions…

You’re trying to use javascript like you would through the URL bar.

Remove the ‘javascript:’:

<?php
echo '<script type="text/javascript">alert("hello!");</script>';
?>
1 Like

thanks, it worked, honestly I tried this earlier, but that didnt work :frowning: the only difference was that I was trying in double questions with \" but its working in single quotes. thanks

Save yourself some future headaches when writing JS inside PHP, look at using the PHP heredoc syntax when possible.

http://www.hudzilla.org/phpbook/read.php/2_6_3

set as resolved :slight_smile: