title: Run JavaScript function on form submit
body: <p>Trying to get back into Javascript, having a little trouble with this very basic thing.</p>
  
  <p><a href="https://jsfiddle.net/gfitzpatrick2/aw27toyv/3/" rel="nofollow noreferrer">https://jsfiddle.net/gfitzpatrick2/aw27toyv/3/</a></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>var name = document.getElementById("name");
  function validate() {
    alert("Your name is " +name);
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form action="" method="post" name="myForm"&gt;
    &lt;label&gt;Name&lt;/label&gt;
    &lt;input type="text" name="name" id="name" /&gt;
    &lt;input type="submit" name="submit" onclick="validate()" /&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Just wanted a pop up box showing the name you have entered in the field, not sure why it's not working. Am I way off?</p>
  
  <p>Thanks.</p>