views:

110

answers:

1

Hi I have this php code which ends up with xml data in a string, I then use onClick to send it to a js function

$strXML = "<chart><set label='B' value='12' /><set label='C' value='10'/></chart>"

<td align='right' onClick='drawchart($strXML)' >&pound $totalcost  </td>

However when it gets to my js function it does not work and the data is corrupt

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

         chart1.setDataXML(dataX);
         chart1.render("chart1div");
}

Can anyone tell me how to correctly send the xml data via a js variable ?

Thanks

+1  A: 

Looks to me like you are getting mixed js and php. I'd say you need to quote the data:

onClick='drawchart("$strXML");'

Also, you should probably need to escape all that XML data to avoid the corruption.

Victor Jalencas