Click here to Skip to main content
15,915,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to
read and display text file value in text box using Javasacript

Here is my code code is correct but value is not display in textbox please give me solution.

What I have tried:

  <div id="page-wrapper">
      
      <input type="text" id="allText">

    </div>

<script>
    var allText = document.getElementById('allText');
function readTextFile(file) {
    var rawFile = new XMLHttpRequest();
    rawFile.open("GET", file, false);
    rawFile.onreadystatechange = function () {
        if (rawFile.readyState === 4) {
            if (rawFile.status === 200 || rawFile.status == 0) {
                var allText = rawFile.responseText;
                alert(allText);
            }
        }
    }
    rawFile.send(null);
}
readTextFile("file:///C:/MACID.txt");

</script>
Posted
Updated 19-Sep-17 0:23am
Comments
F-ES Sitecore 19-Sep-17 6:05am    
You can't read text files like that, google "html5 file api" for ways to read text files from js.

1 solution

Quote:
JavaScript
readTextFile("file:///C:/MACID.txt");

JavaScript and WebApps do not have direct access to user file system for security reasons.
The only way to read a local file is through 'open file' dialog and with user approval.
 
Share this answer
 
Comments
Member 13339456 19-Sep-17 6:52am    
Here is link of solution its read value of input text file
https://codepen.io/matt-west/pen/KjEHg

But i want to read Local Fixed Path Text file

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900