I have following Code which doesn't seems to work correctly when i added the script to add the values in the total that are shown in the total text box
<tbody id='table'>
<tr class="crow">
<td style='width:150px;'>1</td>
<td style='width:350px;'>
<select class="form-control FID" required name="FID[]">
<?php
$options="<option value='' Amount='0' >Select</option>";
foreach($data["challan"] as $row){
$options.="<option value='{$row["FID"]}' Amount='{$row["Amount"]}'>{$row["Feetype"]}</option>";
}
echo $options;
?>
</select>
</td>
<td>
<input type="text" name="Amount[]" class="form-control Amount" required>
</td>
<td>
<input type="button" value="Remove" class="btn btn-link btn-xs rmv" required>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td ><input type='button' class='btn btn-link add' value='+Add Row'></td>
<td colspan="2" class="text-right">Total</td>
<td><input type="text" name="grand_total" id="grand_total" class="form-control" required=""></td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$("body").on("click",".add",function(){
var i=1;
$(".crow").each(function(){
i++;
});
var options="<?php echo $options; ?>";
var row='<tr class="crow"> <td>'+i+'</td> <td> <select class="form-control FID chosen" required name="FID[]">'+options+'</select></td><td> <input type="text" name="Amount[]" class="form-control Amount" required> </td></td><td> <input type="button" value="Remove" class="btn btn-link btn-xs rmv" required> </td></tr>';
$("#table").append(row);
});
$("body").on("click",".rmv",function(){
if(confirm('Are You Sure?')){
$(this).parents('tr').remove();
}
});
$("body").on("change",".FID",function(){
var p=$(this).find(":selected").attr("Amount");
$(this).closest("tr").find(".Amount").val(p);
});
$("body").on("keyup",".Amount",function(){
var Amount=Number($(this).val());
$(this).closest("tr").find(".total").val(Amount*1);
grand_total();
});
function grand_total(){
var tot=0;
$(".total").each(function(){
tot+=Number($(this).val());
});
$("#grand_total").val(tot);
}
});
</script>
I want to get little help that How can show the total amount in the total box, it will add all the values that are shown in the total column to show total in total text box at the end. i try to use the code but some how script doesn't seems to work correctly. Thanks