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

Popular posts from this blog

Delphi change the assembly code of a running process -

java - Parsing XML, skip certain tags -

c# - ASP.NET MVC Sequence contains no matching element -