title: How to store inputs from a textbox in array in Javascript
body: <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
  
  &lt;head&gt;
  
  
  &lt;form id="form1"&gt;
  
  
  Beets:&lt;input id="number1" type="integer" size = "5"&gt;
  
  Artichokes: &lt;input id="number2" type="integer" size = "5"&gt;
  
  Carrots: &lt;input id="number3" type="integer" size = "5"&gt;
  
  &lt;/form&gt;
  
  &lt;button id = "submitButton" onclick="RunApp()" &gt; Submit&lt;/button&gt;
  &lt;button id = "displayButton" onclick="getAllValues()" &gt; Display&lt;/button&gt;
  
  &lt;script&gt;
  
  
  var str = "";
   function getAllValues() {
       var input1, inputs;
    input1 = document.getElementById("form1");
  
    inputs = input1.elements["number1"].value;
  
       for (i = 0; i &lt; inputs.length; i++) {
           str += inputs[i].value + "  ";
       }
       alert(str);
   }
  
  
  function RunApp()
  
  {
  
  var beets, artichokes, carrots, input1, input2, input3;
  
  
  // getting inputs into variables
  
  
  input1 = document.getElementById("form1");
  
  beets = input1.elements["number1"].value;
  
  
  input2 = document.getElementById("form1");
  
  artichokes = input1.elements["number2"].value;
  
  
  input3 = document.getElementById("form1");
  
  carrots = input1.elements["number3"].value;
  
  
  
  
  if (beets == "" || carrots == "" || artichokes == "" || isNaN(beets) || isNaN(carrots) || isNaN(artichokes))
  
  {
  
      document.getElementById("demo").innerHTML+= "not valid" + "&lt;br&gt;";
  
      document.getElementById("demo").innerHTML+= "--------------------------" + "&lt;br&gt;";
  
  }
  
  else
  
  {
  
  
  document.getElementById("demo").innerHTML+= "Beets = " + beets + "&lt;br&gt;";    document.getElementById("demo").innerHTML+= "Artichokes = " + artichokes + "&lt;br&gt;";
  document.getElementById("demo").innerHTML+= "Carrots = " + carrots + "&lt;br&gt;";
  
  
  }
  }
  
  
  
  
  &lt;/script&gt;
  
  
  &lt;p id="demo"&gt;&lt;/p&gt;
  
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>First, this is my first time learning JS. </p>
  
  <p>So, I have a text-box, a submit button, and a display button. When I enter a number in the text-box, and click submit, it shows the number. I enter my second number and clicking the submit button shows me the second number. Then I click on the display button, it will shows the number 1 and number 2 in order. If I have more inputs in the text-box, the display button will show the entire list of all the inputs from the array.</p>
  
  <p>Thank you!</p>