Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript return variable from addEventListener
    text
    copied!<pre><code> var jobj = []; var keyChartData = null; var chartData = [{ "name": "John", "points": 35654, "color": "#7F8DA9", "bullet": "0.gif" }, { "name": "Damon", "points": 65456, "color": "#FEC514", "bullet": "1.gif" }, { "name": "Patrick", "points": 45724, "color": "#DB4C3C", "bullet": "2.gif" }, { "name": "Mark", "points": 13654, "color": "#DAF0FD", "bullet": "3.gif" } { "name": "Mark", "points": 43244, "color": "#DAF0FD", "bullet": "3.gif" } { "name": "Patrick", "points": 64643, "color": "#DB4C3C", "bullet": "2.gif" }, { "name": "Patrick", "points": 73724, "color": "#DB4C3C", "bullet": "2.gif" }, { "name": "John", "points": 65672, "color": "#DB4C3C", "bullet": "2.gif" }, ]; var select = document.getElementById("selector"); var lookup = {}; var len = chartData.length; for (var i = 0; i &lt; len; i++) { var item = chartData[i]; var name = item.name; var option = document.createElement("option"); option.value = i; option.textContent = name; select.appendChild(option); }; select.addEventListener('change', function () { var selValue = select.options[select.selectedIndex].name; for (var i = 0; i &lt; len; i++) { var item = chartData[i]; var name = item.name; //alert("selValue: "+selValue+" Key: " +key); if(selValue === name){ jobj.push(JSON.stringify(chartData[i])); } } keyChartData = JSON.parse(JSON.stringify(jobj)); }) alert(keyChartData); AmCharts.ready(function () { // SERIAL CHART chart = new AmCharts.AmSerialChart(); chart.pathToImages = "http://www.amcharts.com/lib/3/images/"; chart.dataProvider = keyChartData; .......... } </code></pre> <p>This is with reference to <a href="https://stackoverflow.com/questions/20786152/javascript-json-display-data-corresponding-to-option-selected">Javascript JSON Display data corresponding to option selected</a>. which I had asked y'day. Thank you for the solution, I could solve the problem. But now, I have keyChartData declared as global variable, Now I load the JSON data depending on the selected option and store it to keyChartData, which i nedd to capture in AmCharts.ready function to plot the graph. Outsite the function the value of keyChartdata is blank, how to go about this hurdle. Kindly help.</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