title: ReferenceError: Can't find variable X when calling JS function (or variable) from HTML file
body: <p>I am trying to call a function in an external JavaScript file from an HTML-file. The goal is to work with the content of a form there.</p>
  
  <p>I tried so many things and always got the Error "<em>ReferenceError: Can't find variable: X</em>"</p>
  
  <ul>
  <li>The positioning of the jquery javascript file loading</li>
  <li>The positioning of the <code>&lt;script src="XXX"&gt;</code> call</li>
  <li>Calling the function from the button "onclick" or the form "onsubmit"</li>
  <li>Trying to call the javascript file from an embedded script in the HTML</li>
  </ul>
  
  <p>This is what my JavaScript file and my HTML looks like right now:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function submit(e) {
  
    answerText = document.getElementById("text").value;
    // Do something with it.
  
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;head&gt;
    &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"&gt;&lt;/script&gt;
    &lt;script src="/scripts/debug_alerts.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;form id="validation-form" onsubmit="return submit(e)"&gt;
      &lt;input type="text" class="form-control" name="text" id="text" placeholder="Text" required&gt;
      &lt;button type="button" class="btn btn-primary" onclick="submit(e)"&gt;Send&lt;/button&gt;
    &lt;/form&gt;
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I also tried</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function doSomething() {
  
    // Do something
  
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;head&gt;
    &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"&gt;&lt;/script&gt;
    &lt;script src="/scripts/debug_alerts.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;form id="validation-form" onsubmit="return submit(e)"&gt;
      &lt;input type="text" class="form-control" name="text" id="text" placeholder="Text" required&gt;
      &lt;button type="button" class="btn btn-primary" onclick="submit(e)"&gt;Send&lt;/button&gt;
    &lt;/form&gt;
    &lt;script&gt;
      function submit(e) {
        doSomething();
      }
    &lt;/script&gt;
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>In both cases, it returned the same error over and over again: "<em>ReferenceError: Can't find variable: X</em>". In the first example, X being "submit" and in the second "doSomething".</p>
  
  <p>All help is very welcome. I know there are similar headlines here, but non of the solutions did anything for me.</p>