title: Adding dynamic row jquery having dynamic dropdown in php
body: <p>I am using the following jquery code to add new rows but thing is I have couple of static fields and couple of dynamic fields being populated using php.</p>
  
  <pre><code>$(document).on('click', '#add', function(){ 
          if(i &lt; maxField){ //Check maximum number of input fields
              i++;
              var product_dd = '&lt;select name="product_id[]" id="product_id"&gt;&lt;?php echo fill_unit_select_box($products_list); ?&gt;&lt;/select&gt;';
              var category_dd = '&lt;select name="category_id[]" id="category_id"&gt;&lt;?php echo fill_unit_select_box($category_list); ?&gt;&lt;/select&gt;';
  
              $('#dynamic_field').append('&lt;tr id="row'+i+'" class="dynamic-added"&gt;&lt;td&gt;&lt;input id="item_type" pattern="[2-3]*" type="text" required maxlength="1" name="item_type[]" /&gt;&lt;/td&gt;&lt;td&gt;'+product_dd+'&lt;/td&gt;&lt;td&gt;'+category_dd+'&lt;/td&gt;&lt;td&gt;&lt;select name="status[]" id="status"&gt;&lt;option value="1" selected="selected"&gt;Enabled&lt;/option&gt;&lt;option value="0"&gt;Disabled&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove"&gt;X&lt;/button&gt;&lt;/td&gt;&lt;/tr&gt;');
          }
  
      });
  </code></pre>
  
  <p>The rows are being inserted as I need but the problem I am facing is that the two drop downs are blank, I have checked the php function and it is returning all the options I need, but not sure when I click 'Add More' button why the drop downs are blank. Any help please!</p>
  
  <p>here is the php code used to generate the drop downs, which is working fine, I already tested that.</p>
  
  <pre><code>function fill_select_box($products_list)
      {    
           $output = '';   
           foreach($products_list as $key =&gt; $value)
           {
            $output .= '&lt;option value="'.$key.'"&gt;'.$value.'&lt;/option&gt;';
           }
           return $output;
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/HyyTY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HyyTY.png" alt="enter image description here"></a></p>