Mick
Mick

Reputation: 2898

Send XML in a js variable

I have this php code and the variable is XML data

$strXML = "<chart caption='ADI Chart Test ' xAxisName='Month' yAxisName='Units'"
$strXML.= "showValues='0'formatNumberScale='0' showBorder='1'>";

echo "<td align='right' onClick='drawchart($strXML)' > $totalcost </td> " ;` 

this is passed to a javascript function

function drawchart(dataX) {
var chart1 = new FusionCharts("../charts/Pie3D.swf", "chart1Id", "400", "300","1"); 
chart1.setDataXML(dataX);
chart1.render("chart1div");

My problem is that the link is not displayed correctly and more importantly there is no data when it gets to the js function

Could anyone tell me how to send xml data via a js variable please ?

Upvotes: 1

Views: 1303

Answers (3)

malonso
malonso

Reputation: 2295

What is the end result you are looking for - ignoring the XML/JS portion?

If you are just trying to assign other attributes to the chart, couldn't you just load the data via the setDataURL function:

var url="/path/to/data.php";

var chart1 = new FusionCharts("../charts/Pie3D.swf", "chart1Id", "400", "300","1");

url=escape(url);

chart1.setDataURL(url);

chart1.addParam("WMode", "Transparent");

chart1.render("chart1div");

Upvotes: 0

sudi
sudi

Reputation: 1

Seems you have missing something in this : echo "<td align='right' onClick='drawchart($strXML)' > $totalcost </td> " ;`

it should be:

echo "<td align='right' onClick='drawchart(\"$strXML\")' > $totalcost </td> " ;`

Upvotes: 0

Alex Gyoshev
Alex Gyoshev

Reputation: 11967

You should encode the strXML in order to render it as valid HTML. Furthermore, you should enclose it with apostrophes so that it becomes a valid Javascript literal.

echo
     "<td align='right' onClick='drawchart(\"" .
     htmlspecialchars(json_encode($strXML)) . 
     "\")'> $totalcost </td>";

Upvotes: 1

Related Questions