I have recently gotten into html, css, and javascript and am writing a simple website. I need to have an autocomplete textbox. I have a textfile in the same folder as the html and need to read the textfile by newline in order to set the autocomplete sources (i can do that). What i can't do (yet) is get the file text.
I have seen examples with the FileReader()
but all of them use the a file object like this.files[0] or from a <input type=file>
object event. How can I use a string for the file location ( "search.txt" ) and get the result?
my code:
<body onload="ReadFile()">
<script>
var data="";
function ReadFile()
{
var fr=new FileReader();
fr.readAsText("search.txt");
data=fr.responseText;
}
</script>