title: Replace innerhtml on form submit with javascript
body: <p>I want to have a form that asks the user their name, then welcomes them to the website with that name without redirecting to a different page or reloading. So basically replace a form with "Welcome NAME" after submit is clicked.</p>
  
  <p>My code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="welcomeText"&gt;
   &lt;form onsubmit="changeText()" method="post"&gt;
    Name: &lt;input type="text" name="fname"&gt;
    &lt;input type="submit"&gt;
   &lt;/form&gt;
  &lt;/div&gt;
          
          &lt;script&gt;
              function changeText() {
              var name = document.getElementById(welcomeForm).fname.value;
              var welcome = "Welcome, " + name;
              document.getElementById("welcomeText").innerHTML = welcome;
              }
          &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>