I want to create a table that can auto calculate some values for each fields for each rows. I found these jquery calculator, I would like to ask how am I going to use it incase I’ll be using jstl forEach, how can I use this so I would it can auto calculate what ever user entered on a field for each rows.. Thanks..
<html>
<head>
<script type="text/javascript" src="js/jquery-latest.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
$(document).ready(function()
{
$('input').change(function()
{
var ProductUnitVal = parseInt($('#product-unit-val').val());
var TotalUnitSales = parseInt($('#total-unit-sales').val());
var answer = ProductUnitVal * TotalUnitSales;
$('#sales-val').html('$' + answer);
});
});
</script>
</head>
<body>
Unit Value <input type="text" id="product-unit-val" /><br />
Unit Sales <input type="text" id="total-unit-sales" /><br />
<span id="sales-val"></span>
</body>
</html>
Make it row based. When an input changes, look for the closest row (tr) which finds the scope of the elements. Then search just that scope (i.e. the row) for the various elements. Note, I changed from id to class for the 3 items.
And then your script: