-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.js
29 lines (24 loc) · 821 Bytes
/
upload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function readTextFile(file) {
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function () {
if (rawFile.readyState === 4 && rawFile.status === 200) {
document.getElementById("inputBox").value = rawFile.responseText;
}
};
rawFile.send(null);
}
var fileInput = document.getElementById("fileInput");
var submitButton = document.getElementById("submitButton");
var textArea = document.getElementById("textbox");
submitButton.addEventListener("click", function() {
var file = fileInput.files[0];
var reader = new FileReader();
reader.onload = function(event) {
var contents = event.target.result;
textbox.value = contents;
};
reader.readAsText(file);
var contextss = reader.readAsText(file);
});
readTextFile(contextss);