-1

table is under loop

<table>
<tr><input class="txt form-control"  name="balance[]" type="text" placeholder="Balance" /></tr>
</table>

,and the balance is added from all the tr

total balance is shown on the debtsum. And it is done by jquery

<div class="col-lg-3"> <input class="debtsum form-control " id="debt" type="text" name="totaldebt" placeholder="Total Debt" disabled /> </div>

Query to store data into database :

    $totaldebt = mysqli_real_escape_string($connect,$_POST['totaldebt']);//to store total debt in the database
    $table_customer_data="insert into
   tbl_customer_data(totaldebt) values ('".$totaldebt."');

Jquery script to add all the data of class txt :

<script>
function calculateSum() {
var sum = 0;
$(".txt").each(function () {

//add only if the value is number
if (!isNaN(this.value) && this.value.length != 0) {
sum += parseFloat(this.value);      
}
});
$('#debt').val(sum.toFixed(2));
}

$("table").on("keyup", ".txt", function () {
calculateSum();
});

</script>

The jquery function is working properly, and sums all the input value of balance. But when i submit form to store all the value into database it stores nothing.

Thanks in advance, any help is appreciated.

Nehal
  • 1,542
  • 4
  • 17
  • 30
khalil
  • 5
  • 8

1 Answers1

1

I think this is issue due to disabled property in your element.

disabled element isn't editable and isn't sent on submit.

I think you can take readonly.

a readonly element is just not editable, but gets sent when the according form submits.

for more information please click here

Community
  • 1
  • 1
Apoorva
  • 218
  • 3
  • 14