title: Generate text box
body: <p>How do I generate n number of input text box in JavaScript using a select option. And how do I fetch the variables in PHP. </p>
  
  <p>below is my html form</p>
  
  <pre><code>&lt;HTML&gt;
      &lt;HEAD&gt;
          &lt;TITLE&gt;Dynamically add Textbox in html Form using JavaScript&lt;/TITLE&gt;
          &lt;SCRIPT language="javascript"&gt;
              var numberOfElementsAdded;
              var arrayOfInputs = new Array();
              function addToDatabase(numberOfElementsAdded) {
                  numberOfElementsAdded = numberOfElementsAdded * numberOfElementsAdded;
                  var alltext = "";
                  for (var j = 1; j &lt;= numberOfElementsAdded; j++) {
                      var tvalue = document.getElementsByName("text" + j)[0].value;
                      arrayOfInputs.push(tvalue);
                      alltext = alltext + tvalue + " ";
                  }
                  alert(alltext);
              }
  
              function add(type, num) {
                  numberOfElementsAdded = num;
                  //Create an input type dynamically.
                  var k = 0;
                  for (var j = 0; j &lt; num; j++) {
                      for (var i = 0; i &lt; 4; i++) {
                          var element = document.createElement("input");
                          k = k + 1;
                          //Assign different attributes to the element.
                          element.setAttribute("type", type + k);
                          element.setAttribute("id", type + k);
                          element.setAttribute("name", type + k);
                          element.setAttribute('width', '30');
                          element.setAttribute('border', '3px solid #FF0000');
  
                          var foo = document.getElementById("fooBar");
                          //Append the element in page (in span).
                          foo.appendChild(element);
                      }
                      var breakLoop = document.createElement('br')
                      foo.appendChild(breakLoop)
                  }
                  var element = document.createElement("input");
                  element.setAttribute("type", "button");
                  element.setAttribute("id", "Submit");
                  element.setAttribute("name", "Insert into database");
                  element.setAttribute("value", "Insert into database");
                  element.setAttribute("onclick", "addToDatabase(numberOfElementsAdded)");
                  var breakLoop = document.createElement('br')
                  foo.appendChild(breakLoop)
                  foo.appendChild(element);
              }
          &lt;/SCRIPT&gt;
      &lt;/HEAD&gt;
      &lt;BODY&gt;
          &lt;FORM&gt;
          &lt;H2&gt;Dynamically add element in form.&lt;/H2&gt;
          &lt;SELECT name="element"&gt;
              &lt;OPTION value="1"&gt;1&lt;/OPTION&gt;
              &lt;OPTION value="2"&gt;2&lt;/OPTION&gt;
              &lt;OPTION value="3"&gt;3&lt;/OPTION&gt;
              &lt;OPTION value="4"&gt;4&lt;/OPTION&gt;
              &lt;OPTION value="5"&gt;5&lt;/OPTION&gt;
              &lt;OPTION value="6"&gt;6&lt;/OPTION&gt;
              &lt;OPTION value="7"&gt;7&lt;/OPTION&gt;
              &lt;OPTION value="8"&gt;8&lt;/OPTION&gt;
              &lt;OPTION value="9"&gt;9&lt;/OPTION&gt;
              &lt;OPTION value="10"&gt;10&lt;/OPTION&gt;
          &lt;/SELECT&gt;
          &lt;INPUT type="button" value="Add" onclick="add('text',document.forms[0].element.value)"/&gt;
          &lt;BR/&gt;
          &lt;span id="fooBar"&gt;&amp;nbsp;&lt;/span&gt;
          &lt;/FORM&gt;
      &lt;/BODY&gt;
  &lt;/HTML&gt;
  </code></pre>
  
  <p>It generates the text box. But I want to fetch the values of text box as a PHP variable. </p>