title: Uncaught TypeError: projected.value is undefined
body: <p>I'm currently trying to build a find and replace program using regular expressions in JavaScript, but I keep getting the following error when I click the &quot;go&quot; button, which is supposed to find and replace the given string, although currently all I'm trying to do is print the found string onto the console:</p>
  <p><code>Uncaught TypeError: projected.value is undefined</code></p>
  <p>Here's the code:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;body&gt;
      &lt;textarea name=&quot;input&quot; id=&quot;inputText&quot; cols=&quot;30&quot; rows=&quot;10&quot;&gt;
      &lt;/textarea&gt;
      &lt;p id=&quot;projectedText&quot;&gt;&lt;/p&gt;
      &lt;label for=&quot;find&quot;&gt;Find: &lt;/label&gt;
      &lt;input type=&quot;text&quot; id=&quot;find&quot;&gt;
      &lt;label for=&quot;replace&quot;&gt;Replace: &lt;/label&gt;
      &lt;input type=&quot;text&quot; name=&quot;&quot; id=&quot;replace&quot;&gt;
      &lt;input type=&quot;button&quot; value=&quot;Go&quot; id=&quot;commit&quot;&gt;
  &lt;/body&gt; 
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>document.getElementById(&quot;commit&quot;).onclick=findNreplace; //set up go button
  
  //variables
  var textToShow = document.getElementById(&quot;inputText&quot;);
  var projected = document.getElementById(&quot;projectedText&quot;);
  var toFind = document.getElementById(&quot;find&quot;).value;
  var toReplace = document.getElementById(&quot;replace&quot;).value; 
  
  // set up text area to project the input into the paragraph
  textToShow.addEventListener('input',updateValue);
  
  function updateValue(text) {
      projected.textContent=text.target.value;
  }
  
  // replace function
  function findNreplace() {
      var regex = /toFind/;
      var found = projected.value.match(regex);
      console.log(found);
  }
  </code></pre>
  <p>What am I missing?</p>