jquery - Add dynamic sr.no to table row -
i want add dynamic sr.nos dynamically added row. have completed dynamically row adding functinality, stuck in dynamically add sr.no pls me sort out this. suggest me if updation require in row adding code.
my code follows
$(document).ready(function() { $('.del').live('click', function() { $(this).parent().parent().remove(); }); $('.add').live('click', function() { $(this).val('delete'); $(this).attr('class', 'del'); var appendtxt = "<tr> <td>1</td> <td> <select id='additems' name='additems' class='form-control' required='required'> <option selected>-- select --</option> <option><a href='' id='addnewpo'>add new</a></option> <option value='1'> abc </option> <option value='2'> services </option> <option value='3'> js enterprises</option> </select> </td> <td><input type='text' class='form-control'></td> <td><input type='text' class='form-control'></td> <td><input type='text' class='form-control'></td> <td><input type='text' class='form-control'></td> <td><input type='text' class='form-control' disabled></td> <td> <select id='tax' name='tax' class='form-control' required='required'> <option selected>-- select --</option> <option>na</option> <option value='0'> 0 </option> <option value='3'> 3% </option> <option value='5'>5%</option> <option value='12'>12%</option> <option value='18'>18%</option> <option value='28'>28%</option> </select> </td> <td width='2%'><input type='button' class='add' value='add more' /> </td> </tr>"; $("tr:last").after(appendtxt); }); });
<table id="potable" class="table table-bordered table-striped dt-responsive nowrap" width="100%"> <thead> <tr> <th width="5%">sr.no</th> <th width="20%">items</th> <th>description</th> <th>price</th> <th>qty</th> <th>unit</th> <th>amount</th> <th>tax</th> <th></th> </tr> </thead> <tbody> <tr> <td>1</td> <td> <select id="additems" name="additems" class="form-control" required="required"> <option selected>-- select --</option> <option><a href="" id="addnewpo">add new</a></option> <option value="1"> abc </option> <option value="2"> services </option> <option value="3"> js enterprises</option> </select> </td> <td><input type="text" class="form-control"></td> <td><input type="text" class="form-control"></td> <td><input type="text" class="form-control"></td> <td><input type="text" class="form-control"></td> <td><input type="text" class="form-control" disabled></td> <td> <select id="tax" name="tax" class="form-control" required="required"> <option selected>-- select --</option> <option>na</option> <option value="0"> 0 </option> <option value="3"> 3% </option> <option value="5">5%</option> <option value="12">12%</option> <option value="18">18%</option> <option value="28">28%</option> </select> </td> <td width="2%"> <input type='button' class='add' value='add more' /> </td> </tr> </tbody> </table>
i think below code helps you,and not forget add jquery js.
var noofrows = document.getelementbyid('potable').rows.length - 1; var rowid = noofrows + 1; var appendtxt = "<tr id="+rowid+"> <td>"+rowid+"</td> <td> <select id='additems' name='additems' class='form-control' required='required'> <option selected>-- select --</option> <option><a href='' id='addnewpo'>add new</a></option> <option value='1'> abc </option> <option value='2'> services </option> <option value='3'> js enterprises</option> </select> </td> <td><input type='text' class='form-control'></td> <td><input type='text' class='form-control'></td> <td><input type='text' class='form-control'></td> <td><input type='text' class='form-control'></td> <td><input type='text' class='form-control' disabled></td> <td> <select id='tax' name='tax' class='form-control' required='required'> <option selected>-- select --</option> <option>na</option> <option value='0'> 0 </option> <option value='3'> 3% </option> <option value='5'>5%</option> <option value='12'>12%</option> <option value='18'>18%</option> <option value='28'>28%</option> </select> </td> <td width='2%'><input type='button' class='add' value='add more' /> </td> </tr>"; $('#potable > tbody:last-child').append(appendtxt);
Comments
Post a Comment