Below Code is calculating Profit for the 1st row. I am generating another row on button click using javascript [Code give below]. How do I differentiate parent row and child rows in javascript for calculating auto profit for different rows?
<!-- Calculate Auto Profit -->
<script type="text/javascript">
$(document).ready(function(e) {
$("input").change(function() {
var finalprofit = 0;
$("input[id=prod_price],input[id=fashionf_price]").each(function() {
finalprofit = parseInt($(this).val()) - finalprofit;
})
$("input[id=profit]").val(finalprofit);
});
});
</script>
<!-- For add New Row and Delete Row -->
<script type="text/javascript">
var html = '<tr><td><input type="date" name="current_date" id="current_date" value="" /></td><td><input type="text" name="cust_name" id="cust_name" value=""/></td><td><input type="text" name="product" id="product" value=""/></td><td><input type="text" name="prod_price" id="price" value="0" /></td><td><input type="text" name="fashionf_price" id="price" value="0" /></td><td><input type="text" name="profit" id="profit" value="0" /></td><td><button class="remove" /> - </td></tr>';
$(function() {
//$('tbody').sortable();
$('#addRow').click(function() {
$('tbody').append(html);
});
$(document).on('click', '.remove', function() {
$(this).parents('tr').remove();
});
});
</script>
<form method="post" action="AddInventoryServlet" name="formBook">
<table class="tablecontent" id="calc">
<thead>
<tr>
<th>Date</th>
<th>Customer Name</th>
<th>Product</th>
<th>Buy Price</th>
<th>Sell Price</th>
<th>Profit</th>
</tr>
</thead>
<tbody>
<tr class="package-row">
<td><input type="date" name="current_date" id="current_date" value="" /></td>
<td><input type="text" name="cust_name" id="cust_name" value="" /></td>
<td><input type="text" name="product" id="product" value="" /></td>
<td><input type="text" name="prod_price" id="prod_price" value="0" /></td>
<td><input type="text" name="fashionf_price" id="fashionf_price" value="0" /></td>
<td><input type="text" name="profit" id="profit" value="0" /></td>
<td><button class="remove" /> -</td>
</tr>
</tbody>
</table>
<div id="trsubmit">
<input type="submit" value="Submit" name="submit" />
</div>
</form>
