The code below is what I have currently. I want to alert(reader.result) outside of onload, but it always returns null. Shouldn't reader.result keep its result after readAsText() is called and finishes?
To be more specific, my final goal is to read the text within files and then save it in a variable for future use. I've just been using alerts as debugging tools (probably bad, I know).
<input type="file" id="fileinput" />
<script type = "text/javascript" id="00">
var contents = [];
function readAFile(evt)
{
var reader = new FileReader();
var test
var file = evt.target.files[0];
if (file)
{
reader.onload = function (element) {
alert("in onload");
this.result = element.target.result;
alert(reader.result);
};
reader.onerror = function (element) {
alert("reader.onerror called - could not load");
};
reader.readAsText(file);
alert(reader.result);
}
else
{
alert("if(file) returned false - could not load");
}
}
document.getElementById('fileinput').addEventListener('change', readAFile, false);