Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing innerhtml to write html with A LOT of quotes
    text
    copied!<p>I'm trying to call a function which writes a very long string of html to an element. The string will look similar to this;</p> <pre><code> '&lt;div id='gaugearray8'&gt; &lt;p id='ANCPUB' class='plot' style='height:100px;width:175px;float:left;' title='0.0011217599587192' onClick=LowerLevelPrint([{"NumberSelected":1,"TargetPerc":[237.5],"KpiDescription":["Contribution&amp;nbspof&amp;nbspExternal&amp;nbspRevenue"],"KpiName":["revcontrubionkpi"],"ValuetoPrint":[0.0011217599587192],"ValueNow":[19],"ValueCompare":[1693767],"Target":["8"],"KpiUnits":["Pounds"],"PercentCompare":[0.0011217599587192]}]) onmouseover=TopLevelLabel({"NumberSelected":1,"Description":["Contribution&amp;nbspof&amp;nbspExternal&amp;nbspRevenue"],"GroupDescription":"Ancillary&amp;nbspService&amp;nbspPerformance"}) onmouseout=clearnew()&gt;&lt;/p&gt; &lt;p id='CSPUB' class='plot' style='height:100px;width:175px;float:left;' title='21.855170547342' onClick=LowerLevelPrint([{"NumberSelected":7,"TargetPerc":[206.03360584712,8.8767313176762,10.356186537289,12.5,12.5,237.5,10.356186537289],"KpiDescription":["Operating&amp;nbspCost&amp;nbspper&amp;nbspService&amp;nbspKm","Revenue&amp;nbspper&amp;nbspService&amp;nbspKm","Total&amp;nbspCost&amp;nbspper&amp;nbspService&amp;nbspKm","Claims&amp;nbspCost&amp;nbspper&amp;nbspVehicle","Claims&amp;nbspCost&amp;nbspper&amp;nbspDriver","Number&amp;nbspof&amp;nbspClaims&amp;nbspLodged&amp;nbspper&amp;nbsp100,000km","Overheads&amp;nbspCost&amp;nbspper&amp;nbspService&amp;nbspKm"],"KpiName":["opcostperkmkpi","revenueperkmkpi","totalcostperkmkpi","claimspervehkpi","claimsperdriverkpi","claimslodgedkpi","overheadskpi"],"ValuetoPrint":[110.47252736225,5.6435200058102,5.434671444334,0.35610369406272,0.35829645079956,12.666666666667,18.054408207469],"ValueNow":[10.301680292356,0.62137119223733,0.62137119223733,1,1,19,0.62137119223733],"ValueCompare":[9.32510601353,11.010348002623,11.433463800009,280.81708128079,279.09849449204,150,3.4416591510336],"Target":["5","7","6","8","8","8","6"],"KpiUnits":["Pounds&amp;nbspper&amp;nbspKm","Pounds&amp;nbspper&amp;nbspKm","Pounds&amp;nbspper&amp;nbspKm","Pounds&amp;nbspper&amp;nbspVehicle","Pounds&amp;nbspper&amp;nbspDriver","Claims","Pounds&amp;nbspa&amp;nbspkm"],"PercentCompare":[110.47252736225,5.6435200058102,5.434671444334,0.35610369406272,0.35829645079956,12.666666666667,18.054408207469]}]) onmouseover=TopLevelLabel({"NumberSelected":7,"Description":["Operating&amp;nbspCost&amp;nbspper&amp;nbspService&amp;nbspKm","Revenue&amp;nbspper&amp;nbspService&amp;nbspKm","Total&amp;nbspCost&amp;nbspper&amp;nbspService&amp;nbspKm","Claims&amp;nbspCost&amp;nbspper&amp;nbspVehicle","Claims&amp;nbspCost&amp;nbspper&amp;nbspDriver","Number&amp;nbspof&amp;nbspClaims&amp;nbspLodged&amp;nbspper&amp;nbsp100,000km","Overheads&amp;nbspCost&amp;nbspper&amp;nbspService&amp;nbspKm"],"GroupDescription":"Core&amp;nbspService&amp;nbspPerformance"}) onmouseout=clearnew()&gt;&lt;/p&gt; &lt;p id='ROPTUB' class='plot' style='height:100px;width:175px;float:left;' title='9.7292765723395' onClick=LowerLevelPrint([{"NumberSelected":2,"TargetPerc":[12.5,207.23684210526],"KpiDescription":["Revenue&amp;nbspExpenditure&amp;nbspper&amp;nbspPassenger&amp;nbspJourney","Cost&amp;nbspPer&amp;nbspHeadcount"],"KpiName":["revexperjourneykpi","coststaffkpi"],"ValuetoPrint":[19.044041148259,0.41451199641943],"ValueNow":[1,16.578947368421],"ValueCompare":[5.2509863437855,3999.6302909519],"Target":["8","8"],"KpiUnits":["Pounds&amp;nbspper&amp;nbspJourney","Pounds&amp;nbspper&amp;nbspStaff"],"PercentCompare":[19.044041148259,0.41451199641943]}]) onmouseover=TopLevelLabel({"NumberSelected":2,"Description":["Revenue&amp;nbspExpenditure&amp;nbspper&amp;nbspPassenger&amp;nbspJourney","Cost&amp;nbspPer&amp;nbspHeadcount"],"GroupDescription":"Resource&amp;nbspOptimisation"}) onmouseout=clearnew()&gt;&lt;/p&gt;&lt;/div&gt;'; </code></pre> <p>Don't worry about disecting that as it's just an example of what can be sent. I'm assuming the problem is the multitude of quotes inside this string, as the javascript on the page entirely stops working when I include this function.</p> <p>The above string is actually generated in a php loops, and the function I'm trying to use calls attempts </p> <pre><code> document.getElementById('financearea').innerHTML = '&lt;?php $myview-&gt;PopulateContent($finance, 8, 'ub', 'UB', $a); ?&gt;'; </code></pre> <p>` Which works correctly when its in the main page body, but won't run when using the innerHTML method.</p> <p>Does anyone have any suggestions on how this could work?</p> <p>This is the code on the php side - its created and echo'd in a loop</p> <p><code>$thisgoesinfile = "&lt;p id='".$Group.$Depot."' class='plot' style='height:100px;width:175px;float:left;' title='".$TotalValuetoPrint."' onClick=LowerLevelPrint(".json_encode($result_set).") onmouseover=TopLevelLabel(".json_encode($Descriptions).") onmouseout=clearnew()&gt;&lt;/p&gt;";</code></p> <p>Edit: I tried removing all the single quotes in the php string so now the string looks like</p> <p><code>document.getElementById('financearea').innerHTML = &lt;div id=gaugearray8&gt;&lt;p id=ANCPUB class=plot style=height:100px;width:175px;float:left; title=0.0011217599587192 onClick=LowerLevelPrint([{"NumberSelected":1,"TargetPerc":[237.5],"KpiDescription":["Contribution&amp;nbspof&amp;nbspExternal&amp;nbspRevenue"],"KpiName":["revcontrubionkpi"],"ValuetoPrint":[0.0011217599587192],"ValueNow":[19],"ValueCompare":[1693767],"Target":["8"],"KpiUnits":["Pounds"],"PercentCompare":[0.0011217599587192]}]) onmouseover=TopLevelLabel({"NumberSelected":1,"Description":["Contribution&amp;nbspof&amp;nbspExternal&amp;nbspRevenue"],"GroupDescription":"Ancillary&amp;nbspService&amp;nbspPerformance"}) onmouseout=clearnew()&gt;&lt;/p&gt;&lt;p id=CSPUB class=plot style=height:100px;width:175px;float:left; title=21.855170547342 onClick=LowerLevelPrint([{"NumberSelected":7,"TargetPerc":[206.03360584712,8.8767313176762,10.356186537289,12.5,12.5,237.5,10.356186537289],"KpiDescription":["Operating&amp;nbspCost&amp;nbspper&amp;nbspService&amp;nbspKm","Revenue&amp;nbspper&amp;nbspService&amp;nbspKm","Total&amp;nbspCost&amp;nbspper&amp;nbspService&amp;nbspKm","Claims&amp;nbspCost&amp;nbspper&amp;nbspVehicle","Claims&amp;nbspCost&amp;nbspper&amp;nbspDriver","Number&amp;nbspof&amp;nbspClaims&amp;nbspLodged&amp;nbspper&amp;nbsp100,000km","Overheads&amp;nbspCost&amp;nbspper&amp;nbspService&amp;nbspKm"],"KpiName":["opcostperkmkpi","revenueperkmkpi","totalcostperkmkpi","claimspervehkpi","claimsperdriverkpi","claimslodgedkpi","overheadskpi"],"ValuetoPrint":[110.47252736225,5.6435200058102,5.434671444334,0.35610369406272,0.35829645079956,12.666666666667,18.054408207469],"ValueNow":[10.301680292356,0.62137119223733,0.62137119223733,1,1,19,0.62137119223733],"ValueCompare":[9.32510601353,11.010348002623,11.433463800009,280.81708128079,279.09849449204,150,3.4416591510336],"Target":["5","7","6","8","8","8","6"],"KpiUnits":["Pounds&amp;nbspper&amp;nbspKm","Pounds&amp;nbspper&amp;nbspKm","Pounds&amp;nbspper&amp;nbspKm","Pounds&amp;nbspper&amp;nbspVehicle","Pounds&amp;nbspper&amp;nbspDriver","Claims","Pounds&amp;nbspa&amp;nbspkm"],"PercentCompare":[110.47252736225,5.6435200058102,5.434671444334,0.35610369406272,0.35829645079956,12.666666666667,18.054408207469]}]) onmouseover=TopLevelLabel({"NumberSelected":7,"Description":["Operating&amp;nbspCost&amp;nbspper&amp;nbspService&amp;nbspKm","Revenue&amp;nbspper&amp;nbspService&amp;nbspKm","Total&amp;nbspCost&amp;nbspper&amp;nbspService&amp;nbspKm","Claims&amp;nbspCost&amp;nbspper&amp;nbspVehicle","Claims&amp;nbspCost&amp;nbspper&amp;nbspDriver","Number&amp;nbspof&amp;nbspClaims&amp;nbspLodged&amp;nbspper&amp;nbsp100,000km","Overheads&amp;nbspCost&amp;nbspper&amp;nbspService&amp;nbspKm"],"GroupDescription":"Core&amp;nbspService&amp;nbspPerformance"}) onmouseout=clearnew()&gt;&lt;/p&gt;&lt;p id=ROPTUB class=plot style=height:100px;width:175px;float:left; title=9.7292765723395 onClick=LowerLevelPrint([{"NumberSelected":2,"TargetPerc":[12.5,207.23684210526],"KpiDescription":["Revenue&amp;nbspExpenditure&amp;nbspper&amp;nbspPassenger&amp;nbspJourney","Cost&amp;nbspPer&amp;nbspHeadcount"],"KpiName":["revexperjourneykpi","coststaffkpi"],"ValuetoPrint":[19.044041148259,0.41451199641943],"ValueNow":[1,16.578947368421],"ValueCompare":[5.2509863437855,3999.6302909519],"Target":["8","8"],"KpiUnits":["Pounds&amp;nbspper&amp;nbspJourney","Pounds&amp;nbspper&amp;nbspStaff"],"PercentCompare":[19.044041148259,0.41451199641943]}]) onmouseover=TopLevelLabel({"NumberSelected":2,"Description":["Revenue&amp;nbspExpenditure&amp;nbspper&amp;nbspPassenger&amp;nbspJourney","Cost&amp;nbspPer&amp;nbspHeadcount"],"GroupDescription":"Resource&amp;nbspOptimisation"}) onmouseout=clearnew()&gt;&lt;/p&gt;&lt;/div&gt;;</code></p> <p>But still not working.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload