I am a javascript noob and have a question about placement of document.getElementById('blahblah').innerHTML statement in the script.
More specifically, I have the following code
function upload(evt) {
if (!browserSupportFileUpload()) {
alert('The File APIs are not fully supported in this browser!');
} else {
var data = null;
var file = evt.target.files[0];
var reader = new FileReader();
reader.readAsText(file);
reader.onload = function(event) {
var csvData = event.target.result;
data = $.csv.toArrays(csvData);
if (data && data.length > 0) {
alert('Imported -' + data.length + '- rows successfully!');
} else {
alert('No data to import!');
}
};
reader.onerror = function() {
alert('Unable to read ' + file.fileName);
};
}
}
It's basically reading a csv file and saving the csv data into a variable called "data".
Now my question is, when I place document.getElementById('blahblah').innterHTML = data[0][0]; at the end of the code, it will not execute.
It only executes when the statement is placed somewhere within the reader.onload function.
Is there a reason this does not execute at the bottom of the code?