title: Javascript/jQuery compare input value to array
body: <p>I'm relatively new to javascript and jquery. Right now I have a list of words in a txt file. I store this list in an array, and I want to compare the contents of that array to some user input. If there's a match, that specific word should be displayed.</p>
  
  <p>I also use <a href="http://jasny.github.io/bootstrap/javascript.html#typeahead" rel="nofollow">Jasny Bootstrap</a> to perform some typeahead functions to predict which words the user would like to search for.</p>
  
  <p>In the current stage, my function finds matches on the first input character. When using more characters the function returns that no match has been found. Why is that?</p>
  
  <p>Here's my HTML:</p>
  
  <pre><code>&lt;div class="container"&gt;
  
    &lt;div class="appwrapper"&gt;
      &lt;div class="content"&gt;
          &lt;h3&gt;OpenTaal Woordenboek&lt;/h3&gt;
          &lt;p&gt;Voer uw zoekopdracht in:&lt;p&gt;
          &lt;p&gt;&lt;input name="searchinput" id="searchinput" data-provide="typeahead" type="text" placeholder="Zoeken..."&gt;
      &lt;p class="dict"&gt;&lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
  &lt;/div&gt; &lt;!-- /container --&gt;
  </code></pre>
  
  <p>And here's the jQuery:</p>
  
  <pre><code>&lt;script src="bootstrap/js/jquery.js"&gt;&lt;/script&gt;
  &lt;script src="bootstrap/js/bootstrap-typeahead.js"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  var data;
  var myArray = [];
  var txtFile = new XMLHttpRequest();
          txtFile.open("GET", "OpenTaal-210G-basis-gekeurd.txt", true);
          txtFile.onreadystatechange = function() {
      if (txtFile.readyState === 4) {  // Makes sure the document is ready to parse.
              if (txtFile.status === 200) {  // Makes sure it's found the file.
              allText = txtFile.responseText;
              data = txtFile.responseText.split("\n"); // Will separate each line into an array
              myArray = [data];
          } //"\r\n" 
      }
  }
  //console.write(data);
  
  searchinput.onkeypress = function() {
  //alert("The function is working!");
  var formInput = document.getElementById("searchinput").value;
  
     if (myArray == formInput) {
     alert("There's a match!");
     $('.dict').append('&lt;div class="result"&gt;' + myArray + '&lt;/div&gt;')
     } else {
        alert("No match has been found..");
     }
   };
  </code></pre>
  
  <p></p>