Hello, help me figure it out, there is a table with fields: sum, quantity, total. Made generation (at pressing the same fields drop out). In the first line, everything counts, but not in others.
<table class="table table-bordered table-hover" id="tab_logic"> <thead> <tr> <th><?php echo $text_product_name; ?></th> <th><?php echo $text_model; ?></th> <th><?php echo $text_price; ?></th> <th><?php echo $text_count; ?></th> <th><?php echo $text_in_total; ?></th> <th> <a id="add_row" class="pull-left"><i class="fa fa-plus" aria-hidden="true"></i></a></th> </tr> </thead> <tbody> <tr id='addr0'> <th class="col-sm-3"> <input type="text" name="product_name" required class="form-control"> </th> <td class="col-sm-3"> <input type="text" name="model_product" class="form-control"> </td> <td > <input type="text" name="total" required class="form-control" id="i1" onchange=simplecheckout_reload()> </td> <td > <img src="/catalog/view/theme/default/assets/images/add/minus.png" border="0" onclick="jQuery(this).next().val(~~jQuery(this).next().val()-1);simplecheckout_reload('cart_value_decreased');"> <input type="text" name="quantity" id=i2 value="1" size="1" onchange="simplecheckout_reload('cart_value_changed')" > <img src="/catalog/view/theme/default/assets/images/add/plus.png" border="0" onclick="jQuery(this).prev().val(~~jQuery(this).prev().val()+1);simplecheckout_reload('cart_value_increased');"> </td> <td > <input type="number" name="oll_total" id=i3> </td> <td> </td> </tr> <tr id='addr1'></tr> </tbody> </table> $(document).ready(function(){ var i=1; $("#add_row").click(function(){ $('#addr'+i).html("<td><input type='text' name='product_name"+i+"' class='form-control'></td>" + "<td><input name='model_product"+i+"' type='text' class='form-control' />" + "</td><td><input name='total"+i+"' type='text' class='form-control' id='i1' onchange=simplecheckout_reload()></td>" + "<td><img src='/catalog/view/theme/default/assets/images/add/minus.png' border='0' onclick=jQuery(this).next().val(~~jQuery(this).next().val()-1);onchange=simplecheckout_reload()>" + "<input type='text' name='quantity' id='i2' value='1' size='1' onchange=simplecheckout_reload()>" + "<img src='/catalog/view/theme/default/assets/images/add/plus.png' border='0' onclick=jQuery(this).prev().val(~~jQuery(this).prev().val()+1);onchange=simplecheckout_reload();></td>" + "<td><input type='number' name='oll_total"+i+"' id='i3'></td>" + "<td><a id='delete_row' style='margin-right:30%;' class='pull-right minus'><i class='fa fa-minus' aria-hidden='true'></i></a></td></td>"); $('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>'); i++; }); $("#delete_row").click(function(){ if(i > 1 ){ $("#addr"+(i-1)).html(''); i--; } }); }); jQuery(document).on('click', '.minus', function(){ jQuery( this ).closest( 'tr' ).remove(); }); function simplecheckout_reload(){ var n1=document.getElementById('i1').value; var n2=document.getElementById('i2').value; document.getElementById('i3').value=Number(n1)*Number(n2); }
document.getElementById- finds a single element on the page. That is why theidattribute must be unique. - Igor