javascript - How to get variable from within the function? -
i'm trying access myvariable outside function. please see code below:
var myvariable; function drawbasic(){ ... myvariable = document.getelementbyid('chart_div3'); var chart = new google.visualization.linechart(document.getelementbyid('chart_div')); google.visualization.events.addlistener(chart, 'ready', function () { chart_div.innerhtml = '<img src="' + chart.getimageuri() + '">'; myvariable.innerhtml = chart.getimageuri(); myvariable = myvariable.innerhtml; //prints out desired value console.log(myvariable); }); //prints out desired value console.log(myvariable); ... } //prints out undefined console.log(myvariable);
i know myvariable defined outside function hoping set inside function , value used anywhere else, wrong. question how can value of chart.getimageuri() , store value outside function drawbasic?
i think because of issue syntax in "var = myvariable". wrote , works fine.
var myvariable; drawbasic(); function drawbasic(){ myvariable = "test string"; //prints out desired value console.log(myvariable); } //prints out undefined console.log(myvariable);
Comments
Post a Comment