Hello.
There is a text file, that a user can choose from their computer to upload. The file is name.txt for example.
I have found this source code:
[CODE]
<html>
<head>
<script>
var openFile = function(event) {
var input = event.target;
var reader = new FileReader();
reader.onload = function(){
var text = reader.result;
var node = document.getElementById(‘output’);
node.innerText = text;
console.log(reader.result.substring(0, 200));
};
reader.readAsText(input.files[0]);
};
</script>
</head>
<body>
<input type=’file’ accept=’text/plain’ onchange=’openFile(event)’><br>
<div id=’output’>
…
</div>
</body>
</html>
source:
I would like to have the whole content of the text file in a string variable that I can further work with. Is that possible? Could you please help me?
Thank you.