I am writing a simple script that will read a .txt file. I had quite a bit of trouble with making it work, now i would like to upgrade it. Basicly i am looking for an option that would halt the program until file is opened and read. I tried putting a while() waiting for some variable to change, but that while halts the whole program - makes it impossible to click on open file.
HTML:
<html>
<head>
</head>
<body>
<input type="file" id="fileInput">
<script src="1dn.js"></script>
</body>
</html>
Javascript:
var string;
window.onload = function() {
var fileInput = document.getElementById('fileInput');
fileInput.addEventListener('change', function(e) {
var file = fileInput.files[0];
var reader = new FileReader();
reader.onload = function(e) {
string = reader.result;
alert(string);
}
reader.readAsText(file);
});
}
*** wait here until file is opened and read
*** do some other stuff