Javascript function argument error
I'm using the following function:
<body onload="testing(<?php print "'". $_SESSION['data'] . "'"; ?>);">
if $_SESSION['data'] = "My name is function"
then it works fine but
if $_SESSION['data'] = "Calling jackson's function"
then it gives error.
Can you tell me how can i pass an argument which may contain characters like
$_SESSION['data'] = "Calling jackson's function"
into the testing functi开发者_开发百科on parameters.
Escape them with addslashes()
echo "'" . addslashes($_SESSION['data']) . "'";
You could do:
<body onload="testing(<?php print "'". addslashes($_SESSION['data']) . "'"; ?>);">
精彩评论