Transferring data from PHP to JavaScript
I have a php variable called $VrHistorySlider defined as follows:
$VrHistorySlider.='<table border="0"><tr><td>(oldest)</td><td style="padding:0px 10px 0px 10px ;"> <div id="note-slider-'.$VrNoteId.'" style="width:'.$VrSliderWidth.'px;background: url(\''.$VrSliderBGImg.'\') repeat-x ;" class="ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all"></div> </td><td>(latest)</td></tr></table>'; Now I want to save it in a JavaScript variable. I tried this:
var slidercontent = <?= $VrHistorySlider ?>; but he gives me this error:
unknown
nbspxml object<parent xmlns=""><table border="0"><tr...td>(latest)</td></tr></table></parent>
If this is not the case, then how do I assign this $VrHistorySlider a JavaScript slidercontent variable?
All you need is quotes around the php variable, because when you try to assign it so that it puts the raw code on the page, rather than making it a string.
You also need to avoid quotation marks in the string, as otherwise they will appear to end in the string and it will not work.
So it should look like this:
var slidercontent = "<?=addslashes($VrHistorySlider)?>";