title: Show more inputs based on select in PHP Foreach Loop
body: <p>I have a PHP Foreach loop that contains a "Quantity" input. Users can select a quantity and then that quantity selected should display the selected # of new inputs. If I choose a quantity of "3" then 3 new inputs should appear for that item. Remember, I have a forreach loop so I have multiple items.</p>
  
  <p>As of right now, my code only works to display the new number of inputs for the FIRST item only. I need it to work for every item in the forreach loop. See my code below:</p>
  
  <pre><code>foreach($rows as $row) {
                   $appareltype = $row['appareltype'];
                      $apparel = explode(",", $appareltype);
                      foreach($apparel as $datapparel) {
                          ?&gt;
                              &lt;b&gt;&lt;? echo $datapparel ?&gt;&lt;/b&gt;&lt;br&gt;
                              Quantity: &lt;select name="quantity[]" class="form-control quantity"&gt;
                              &lt;option value="0" selected="selected"&gt;0&lt;/option&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;option value="11"&gt;11&lt;/option&gt;
                              &lt;option value="12"&gt;12&lt;/option&gt;
                              &lt;option value="13"&gt;13&lt;/option&gt;
                              &lt;option value="14"&gt;14&lt;/option&gt;
                              &lt;option value="15"&gt;15&lt;/option&gt;
                              &lt;option value="16"&gt;16&lt;/option&gt;
                              &lt;option value="17"&gt;17&lt;/option&gt;
                              &lt;option value="18"&gt;18&lt;/option&gt;
                              &lt;option value="19"&gt;19&lt;/option&gt;
                              &lt;option value="20"&gt;20&lt;/option&gt;
  
                              &lt;div id="text"&gt;
  
                              &lt;/div&gt;
  
                          &lt;?
                      }
  
              }
                       ?&gt;
  </code></pre>
  
  <p>jQuery:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $("select.quantity").change(function () {
    var str = "";
    var count = Number($("select option:selected").val())
    for (var i = 0; i &lt; count; i++) {
        str += '&lt;div class="oneinput"&gt; &lt;label&gt;' + i
                + "&lt;/label&gt; &lt;input name='" + i + "' class='form-control'&gt;"
                + "&lt;/div&gt;";
    }
  
    $("#text").html(str);
  });
  &lt;/script&gt;
  </code></pre>