See the image below, I want to add many product as I want by clicking on "Add More Product" and then 2 new elements will be appear (Category and Items dropdowns). This will be done via jQuery to copy previous <li>
and insert a new one.
When the elements are created, what the name of the dynamic fields should be? The data will be added into $_POST and I can insert into database.
HTML below, see dynamic fields name (example: name="items_2"
, name="items_2"
):
I have also added hidden input of current_added_products
field. This tell me how many products currently added. Not sure if I need this?
<ul>
<li>
<label>Category</label>
<select name="category_1">
<option>CPU</option>
<option>HDD</option>
</select>
<select name="items_1">
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
</select>
</li>
<li>
<label>Category</label>
<select name="category_2">
<option>CPU</option>
<option>HDD</option>
</select>
<select name="items_2">
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
</select>
</li>
<li>
<label></label>
<input type="hidden" name="current_added_products" value="2" />
<input type="button" class="add_more_product" value ="Add More Product" />
</li>
</ul>
Also, before the elements are created how to get the next numbers to be added?