Read file content using javascript
We can upload the file using file control and read content of that file using below script 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('codeInTest');
node.value = text;
};
reader.readAsText(input.files[0]);
};
</script>
</head>
<body>
<input type='file' accept='text/plain' onchange='openFile(event)'><br>
<textarea rows="17" cols="129" wrap="virtual" id="fileContent"></textarea>
</body>
<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('codeInTest');
node.value = text;
};
reader.readAsText(input.files[0]);
};
</script>
</head>
<body>
<input type='file' accept='text/plain' onchange='openFile(event)'><br>
<textarea rows="17" cols="129" wrap="virtual" id="fileContent"></textarea>
</body>
Comments
Post a Comment