Jump to content

Java add row plus increment


dsp77

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/192626-java-add-row-plus-increment/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.