I am trying to calling a variable defined in another file. I have the following code in my HTML file surrounded by <script> tags within the body.
function getScript("./analysis_method.js", callback) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "./analysis_method.js";
script.onreadystatechange = callback;
script.onload = callback;
document.getElementsByTagName('head')[0].appendChild(script);
}
getScript('./analysis_method.js', function() {
alert("Analysis Method: " + method);
});
In analysis_method.js I have defined method like this: var method = "thermometer";
I got this code off of another Stack Overflow question and I changed what I understood for my project. I believe my issue is that I have not changed callback although I don't know what to change it to.