An example to write javascript code in php, escaping quotes:
Suppose this is your requirement. You have to display an image, which has an onclick event, to some function that must accept dynamic php parameters. This is the static code:
<img width="210" border="0" onclick="javascript:load_user('qrp3p0s42ebcsf','local','downloads/882381283.pdf',0);"
style="cursor:pointer;" src="images/stories/watch-now.png">
So first what we do is, prepare the javascript onclick part dynamically in php:
$img_js = ' onclick="javascript:load_user(\''.$user['id'].'\',\''.$user['access'].'\',\''.$file_path.'\',0);" ';
Then add that to the image code. Now this is the final code we write entirely in php:
$user_img is the dynamic image url.
<?php
echo '<img width="210" border="0" style="cursor:pointer;"
src="'.$user_img.'"'.$img_js.' />';
?>
Done :)
Suppose this is your requirement. You have to display an image, which has an onclick event, to some function that must accept dynamic php parameters. This is the static code:
<img width="210" border="0" onclick="javascript:load_user('qrp3p0s42ebcsf','local','downloads/882381283.pdf',0);"
style="cursor:pointer;" src="images/stories/watch-now.png">
So first what we do is, prepare the javascript onclick part dynamically in php:
$img_js = ' onclick="javascript:load_user(\''.$user['id'].'\',\''.$user['access'].'\',\''.$file_path.'\',0);" ';
Then add that to the image code. Now this is the final code we write entirely in php:
$user_img is the dynamic image url.
<?php
echo '<img width="210" border="0" style="cursor:pointer;"
src="'.$user_img.'"'.$img_js.' />';
?>
Done :)
Comments
Post a Comment