title: How to display input back to the user on an HTML page?
body: <p>I am new to HTML and I am trying to create a script to display user input in a message box. I have created a textbox and validated it with a regular expression (alphabet only).</p>
  
  <p>Now I need to display the user input in the page itself. How can I do this with JavaScript?</p>
  
  <p>I need to display all the user inputs in the page itself. I need to display the two letter word in one container and three letter word in another container.</p>
  
  <p>This is the code I tried.</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;style type="text/css"&gt;
  
          &lt;/style&gt;
          &lt;script type="text/javascript"&gt;
              function Allow() {
                  if (!user.title.value.match(/[a-zA-Z]$/) &amp;&amp; user.title.value != "") {
                      user.title.value = "";
  
  
                      alert("Please Enter only alphabets");
                  }
              }
  
              var titles = [];
              var titleInput = document.getElementById("title");
              var messageBox = document.getElementById("display");
  
              function insert( ) {
                  titles.push(titleInput.value);
                  clearAndShow();
              }
  
              function clearAndShow() {
                  // Clear our fields
                  titleInput.value = "";
  
                  // Show our output
                  messageBox.innerHTML = "";
                  messageBox.innerHTML += "Titles: " + titles.join(", ") + "&lt;br/&gt;";
  
          &lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;p&gt;form input&lt;/p&gt;
          &lt;form name="user"  action="" onsubmit=" "  method="post"&gt;
  
              User&lt;input id="title" type="text" maxlength="4"  onkeyup=" Allow() " &gt;
                  &lt;input type="submit" value="Save/Show" onclick=" insert() " /&gt;
          &lt;/form&gt;
          &lt;div id="display"&gt;&lt;/div&gt;
      &lt;/form&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>