Thursday, October 25, 2012

PHP/JS - Echo a javascript function

Normally, if you want to echo a javascript function you should use escaping characters otherwise it won't work.

Compilable, but not working:

echo "<li><a href='#' id='lnk_admin' name='lnk_admin'
            onclick='window.location.replace(my_page.php'); '>Click Me</a></li>";

Compilable, AND working:
echo "<li><a href='#' id='lnk_admin' name='lnk_admin'
            onclick=\"window.location.replace('my_page.php');\">Click Me</a></li>";


Cheers!

No comments:

Post a Comment