Read and display the text file using javascript
Welcome back to shortlerner.com, in our previous post we was learn How to Send Attachment With Email with the help of PHP. today in this post we will see how to read and display a text file data into html text area tag with the help of JavaScript.
so here we are creating a file tag where user upload the text file and there is another html form element text area.
so whenever user upload the file we use some JavaScript functions which will read the file and display all the data of the file inside the text area.
Also Read :
PHP Login Script With Remember me.
Unable to create a directory a wordpress error
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?
<input type="file" onchange="onFileSelected(event)">
<br>
<textarea id="result" rows="10" cols="50"></textarea>
<script type="text/javascript">
function onFileSelected(event) {
var selectedFile = event.target.files[0];
var reader = new FileReader();
var result = document.getElementById("result");
reader.onload = function(event) {
result.innerHTML = event.target.result;
};
reader.readAsText(selectedFile);
}
</script>
simply just copy the above code and put it on your root directory.
hope this post will helps you, if you still facing some bugs or error to than feel free to contact.
thanks for reading the post and please share this code with your developer buddy.
keep coding , keep learning