Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP generated javascript not executing
    text
    copied!<p>Following dropdown:</p> <pre><code>&lt;select id='dropdown' name='dropdown' onchange='showChart(this.value)'&gt; &lt;option value="1"&gt;Foo&lt;/value&gt; &lt;option value="2"&gt;Bar&lt;/value&gt; &lt;/select&gt; </code></pre> <p>Calls this javascript function onchange:</p> <pre><code>&lt;script type="text/javascript"&gt; function showChart(str1) { if (str1 == "") { document.getElementById("chartContainer").innerHTML = ""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) { document.getElementById("chartContainer").innerHTML = xmlhttp.responseText; } }; xmlhttp.open("GET", "../ajaxpage/chart.php?charttype=" + str1); xmlhttp.send(); } &lt;/script&gt; </code></pre> <p>chart.php?charttype looks like this:</p> <pre><code>&lt;?php $charttype = $_GET['charttype']; if ($charttype == "1") { echo "&lt;p&gt;test1&lt;/p&gt;"; echo "&lt;script type='text/javascript'&gt; alert('test1'); &lt;/script&gt;"; } else { echo "&lt;p&gt;test2&lt;/p&gt;"; echo "&lt;script type='text/javascript'&gt; $(document).ready(function() { alert('test2'); }); &lt;/script&gt;"; } ?&gt; </code></pre> <p>Everything seems to work. The test1 and test2 in paragraph tags are rendered correctly in the graphContainer div onchange of the dropdown. However, the javascript is not executing. How come generated javascript does not execute, and how do I fix this?</p> <p>Thanks.</p> <p><strong>EDIT</strong></p> <p>Here is the extremely foul (but working) workaround:</p> <pre><code>&lt;img src="../images/loaded.gif" alt="" onload="Code To Execute Here;this.parentNode.removeChild(this);" /&gt; </code></pre>
 

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