Storing php value in javascript variable -
Storing php value in javascript variable -
i trying store php value in javascript variable. code giving me syntax error. code right ?
var b = <?php echo $tagvalue;?>; alert("b " +b);
you have create sure webserver interprets file php file. have adapt code, because looks have error in js code in end:
var b = "<?php echo $tagvalue;?>"; alert("b " +b);
(i have added quotes). not apply, if sure $tagvalue
numeric.
in case don't know kind of value $tagvalue
or want create sure won't fail should utilize json_encode($tagvalue)
:
var b = <?php echo json_encode($tagvalue);?>; alert("b " +b);
please note in case $tagvalue
array/object js-alert won't usefull :)
javascript php
Comments
Post a Comment