Basically I want to be able to load a configuration from a .csv file and use it to setup an HTML page. After some digging I found the common solution of a FileReader and an AddEventListener. My HTML looks like so :
<html>
<head>
<script src="kernel.js"></script>
<script>
var k = new kernel();
</script>
</head>
<body>
<input type="file" id="file-input" />
<script>
document.getElementById('file-input').addEventListener('change', k.loadConfig, false);
</script>
<!-- Tables and stuff that i want to modify -->
</body>
</html>
kernel.js :
function kernel() {
var self = this;
this.config = null;
this.readSingleFile = function(e) {
var file = e.target.files[0];
if (!file) return null;
var reader = new FileReader();
reader.onload = function(e) { self.config = e.target.result; };
reader.readAsText(file);
}
this.loadConfig = function(e) {
self.readSingleFile(e);
console.log(self.config);
// Do more stuff
}
}
Then the console.log() should display the content of the file if I'm not mistaken. But instead it comes up null, and I'm stuck.
If someone can help me or even direct me in the right direction I would be really grateful.
Regards, Dom.