dsp77 Posted February 19, 2010 Share Posted February 19, 2010 i want to add a row to my end of the table but the name from the input forms needs to be different and i dont know how to increment the clone with 1 at every row added, i have this javascript code: $(document).ready(function() { $("#addrow").click(function() { $('#ORDERLINES tbody>tr:last').clone(true).insertAfter('#ORDERLINES tbody>tr:last'); return false; }); }); and the html <table id="ORDERLINES" cellspacing="1" class="tablesorter"> <thead> <tr> <th class="center">Nr. crt</th> <th class="center">Denumire</th> <th class="center">Document justificativ Denumire/ nr./ data</th> <th class="center">UM</th> <th class="center">Cant</th> <th class="center">Valoare totala (lei)</th> <th class="center">Valoare decontata din bugetul proiectului (lei)</th> </tr> </thead> <tr> <td class="center">1</td> <td><input name="item_no1" type="text" id="item_no1" value="" /></td> <td><input name="item-desc1" type="text" id="item-desc1" value="" /></td> <td><input name="item-desc1" type="text" id="item-desc1" value="" /></td> <td><input name="item-desc1" type="text" id="item-desc1" value="" /></td> <td><input name="item-desc1" type="text" id="item-desc1" value="" /></td> <td><input name="item-desc1" type="text" id="item-desc1" value="" /></td> </tr> <tr> <td class="center">2</td> <td><input name="item_no2" type="text" id="item_no2" value="" /></td> <td><input name="item-desc2" type="text" id="item-desc2" value="" /></td> <td><input name="item-desc2" type="text" id="item-desc2" value="" /></td> <td><input name="item-desc2" type="text" id="item-desc2" value="" /></td> <td><input name="item-desc2" type="text" id="item-desc2" value="" /></td> <td><input name="item-desc2" type="text" id="item-desc2" value="" /></td> </tr> </table> <table cellspacing="1" class="tablesorter"> <tr> <td colspan="5"><strong>TOTAL MATERIALE CONSUMABILE, PIESE DE SCHIMB:</strong></td> <td width="97"> </td> <td width="165"> </td> </tr> </table> <br /> <p class="tright"><a id="addrow" href="#"><strong>Adauga Linie</strong></a></p> Quote Link to comment Share on other sites More sharing options...
Axeia Posted February 19, 2010 Share Posted February 19, 2010 var i = 0; $(document).ready(function() { $("#addrow").click(function() { $('#ORDERLINES tbody>tr:last').clone(true).insertAfter('#ORDERLINES tbody>tr:last'); i++; return false; }); }); Could the answer really be that simple? I don't see any form in the given code btw Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 19, 2010 Share Posted February 19, 2010 Could you not just name the fields as arrays? There there is no need to change the name for additional field added. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.