0
I have a value field with the class called .amount-debit
, I automatically sum up everything that belongs to that class.
How fields are included dynamically, how I could only fetch the value of the last added line?
HTML
<div id="debit-after">
<div class="form-group">
<div class="col-md-3">
<div class="form-group">
<label>Amount</label>
<input type="text" class="form-control border-input money disabled-inputs amount-debit" id="debit[0][amount]" name="debit[0][amount]" placeholder="Amount" value="25,000.00">
</div>
</div>
<div class="col-md-1" id='debit-transaction-edit'>
<a href="#" class="remove_field_debit_edit"><i class="fa fa-trash icon-trash"></i></a>
<a href="javascript:;" class="debit-transaction-edit"><i class="fa fa-plus icon-add"></i></a>
</div>
</div>
<div class="form-group">
<div class="col-md-3">
<div class="form-group">
<input type="text" class="form-control border-input money disabled-inputs amount-debit" id="debit[1][amount]" name="debit[1][amount]" placeholder="Amount" value="50,000.00">
</div>
</div>
<div class="col-md-1" id='debit-transaction-edit'>
<a href="#" class="remove_field_debit_edit"><i class="fa fa-trash icon-trash"></i></a>
</div>
</div>
<input type="hidden" id="debit_total_rows" name="debit_total_rows" value="2">
</div>
jQuery of the sum and inclusion
function countamountdebit(){
var total = 0;
$(".amount-debit").each(function(){
total += +(this.value.replace(/,/g, ''));
});
$("#amount_total_debit").text(total.toLocaleString('en-US', { minimumFractionDigits: 2 }));
set_avaliable_balance();
set_balance_total();
}
countamountdebit();
$(document).on("keyup", ".amount-debit", countamountdebit);
$(document).ready(function() {
$('.money').maskMoney();
var max_fields = 100; //maximum input boxes allowed
var wrapper = $("#debit-after"); //Fields wrapper
var add_button = $(".debit-transaction-edit"); //Add button ID
var total_debit = $("#debit_total_rows").val();
var x = total_debit; //initlal text box count
add_button.click(function(e){ //on add input button click
e.preventDefault();
$(wrapper).append('<hr/><div class="note"><div class="col-md-3"><div class="form-group"><input type="text" class="form-control border-input money amount-debit" placeholder="Amount" value="" id="debit['+ x +'][amount]" name="debit['+ x +'][amount]"></div></div><div class="col-md-3"><div class="form-group"><input type="date" class="form-control border-input" placeholder="Date" id="debit['+ x +'][ddate]" name="debit['+ x +'][ddate]"></div></div><div class="col-md-5"><div class="form-group"><input type="text" class="form-control border-input" id="debit['+ x +'][details]" name="debit['+ x +'][details]" placeholder="Details of Transaction"></div></div><div class="col-md-1"><a href="#" class="remove_field_debit_edit"><i class="fa fa-trash icon-trash"></i></a></div></div></div><div><hr/>'); //add input box
$('.money').maskMoney();
$(document).on("keyup", ".amount-debit", countamountdebit);
});
$(wrapper).on("click",".remove_field_debit_edit", function(e){ //user click on remove text
e.preventDefault(); $(this).parent().parent().remove(); x--;
countamountdebit();
})
});
I need to assemble a jQuery where you search for the last added field, with its respective value. And include in a div called "last_deposit"
How can I do that?
In the HTML you passed, in which of the DIV’s/ field specifically is the " value " you want to take ? In this case, the DIV / field that is duplicated(the).
– Leo
In this one @leo
– Sr. André Baill
<input type="text" class="form-control border-input money disabled-inputs amount-Debit" id="Debit[0][amount]" name="Debit[0][amount]" placeholder="Amount" value="25,000.00">
– Sr. André Baill
Because it is dynamic, its return should always be the last value of the field Debit[x][amount]
– Sr. André Baill
Okay, dude, there’s a jQuery function that’s called
last()
, where you look for the last created child of some element in specific, or class, id and the like. It may be a solution for you– Leo
I’m going to add an answer more or less with a logic of this for you to take as an example.
– Leo
Let’s go continue this discussion in chat.
– Sr. André Baill