In my codeigniter view, I have a div containing a select box and a text box. There is also a "Add more" button. My task is to duplicate this entire div when the add more button is pressed, and when I submit the form, I need to get the field values from the original div and the duplicated div. How can i do this? I tried duplicating a div using the jquery clone method . But could not find a solution.
Here is the code I've tried so far:
<?php echo form_open("vehicle/addparts");?> <div class="row" id="addparts"> <div class="col-md-6"> <div class="form-group"> <select class="form-control input-medium" name="parts"> <option value="">select disabled>Select Parts</option> <option value="a">A</option> <option value="b">B</option> <option value="c">C</option> </select> </div> </div> <div class="col-md-6"> <div class="form-group"> <label class="control-label">Quantity</label> <input type="text" name="partsquantity" id="partsquantity"> </div> </div> </div> <div class="row"> <input type="button" name="addmore" value="Add More" onClick="duplicate"> </div> <?php echo form_close();?> Javascript: <script> function duplicate() { var original = document.getElementById('addparts'); var clone = original.cloneNode(true); clone.id = "duplic"; document.bodey.append(clone); } </script>
source share