$('#add').click(function(){ i++; $('#dynamic_field').append('<tr id="row'+i+'"><td><input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" /></td> <td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');
that one is working when i put this code it wont work
<td>
<label for="Category">Category</label>
<select class="form-control" name="product-categorie[]">
<option value="">Select Product Category</option>
<?php
foreach ($all_categories as $cat): ?>
<option value="<?php echo (int)$cat['id'] ?>"><?php echo $cat['name'] ?></option>
<?php
endforeach; ?>
</select>
</td>
the button won't add another field.
The following should help you get going. Based on your info and missing full HTML code, i just put basic selectors.
$(document).ready(function() { var i = 0; $('select').change(function() { i++; $('table tr:last').after('<tr id="row' + i + '"><td><input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" /></td> <td><button type="button" name="remove" id="' + i + '" class="btn btn-danger btn_remove">X</button></td></tr>'); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tr> <td> <label for="Category">Category</label> <select class="form-control" name="product-categorie[]"> <option>Select Product Category</option> <option value="1">Some Name 1</option> <option value="2">Some Name 2</option> </select> </td> </tr> </table>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.