Problem removing a dynamic form field in jquery
- by rshivers
I'm trying to remove a dynamic form field by click a button. It will also subtract whatever values it had from the total amount from my calculation. This is the code:
function removeFormField(id) {
var id = $(id).attr("name");
$('#target1').text($("#total" + id).map(function() {
var currentValue = parseFloat(document.getElementById("currentTotal").value);
var newValue = parseFloat($("#total" + id).text());
var newTotal = currentValue - newValue;
document.getElementById("currentTotal").value = newTotal;
return newTotal;
}).get().join());
$(id).remove();
}
Okay, it will do the subtraction portion of the code with no problem, this issue is with the last line to remove the field. If I comment out the rest of the code it will work, but not with the rest of the code. I know this is something simple, yet I can't seem to wrap my mind around it. Can someone please help?