i have a form in which i want to take out a percentage on a amount for eg. let the amount be 100 and i will enter 10 so the desired output is 10 and i even want to add the percentage's amount with the amount so the output will be 110 (100 + 10) i am able to take out the percentage but its not being added to the amount and these fields will be the dynamically generated inputs.
Here is my code:
$(document).ready(function(){
$('#detail').on('keyup', '.rent, .stperc, .st, .stamt, .cal', calculateRow);
function calculateRow() {
var $row = $(this).closest('tr');
var value = parseFloat($row.find('.stperc').val());
var value2 = parseFloat($row.find('.rent').val());
var stamt = parseFloat($row.find('.stamt').val((value * value2) / 100));
var cost = stamt + value2;
console.log(cost);
if (isNaN(cost)) {
$row.find('.cal').val("0");
} else {
$row.find('.cal').val(cost);
}
}
});
Here is my php code which will generate the textboxes:
while ($row = mysql_fetch_object($query)){
echo "<tr>";
echo "<td align='center'>";
echo "<input type='text' class='form-input-rate' name=\"locno_$ctr\" value=\"$row->locno\" $stylen readonly>";
echo "</td>";
echo "<td align='center'>";
echo "<input type='text' class='form-input-rate' name=\"ledger_$ctr\" value=\"$row->custcode\" $stylen readonly>";
echo "</td>";
echo "<td align='center'>";
echo "<input type='text' class='form-input-rate' name=\"name_$ctr\" value=\"$row->name\" $stylev readonly>";
echo "</td>";
echo "<td align='center'>";
echo "<input type='text' class='form-input-rate' name=\"deposit_$ctr\" value=\"$row->deposit\" $stylen >";
echo "</td>";
echo "<td align='center'>";
echo "<input type='text' class='rent form-input-rate' name=\"rent_$ctr\" value=\"$row->rent\" $stylen >";
echo "</td>";
echo "<td align='center'>";
echo "<input type='text' class='stperc form-input-rate' name=\"stperc_$ctr\" value=\"$row->stperc\" $stylen >";
echo "</td>";
echo "<td align='center'>";
echo "<input type='text' class='stamt form-input-rate' name=\"st_$ctr\" value=\"$row->stamt\" $stylen >";
echo "</td>";
echo "<td align='center'>";
echo "<input type='text' class='cal form-input-rate' name=\"total_$ctr\" value=\"$row->totamt\" $stylen readonly>";
echo "<input type='hidden' name=\"accode_$ctr\" value=\"$row->accode\">";
echo "</td>";
echo "</tr>";
$ctr++;
}