Problem removing a dynamic form field in jquery
Posted
by rshivers
on Stack Overflow
See other posts from Stack Overflow
or by rshivers
Published on 2010-05-25T19:33:42Z
Indexed on
2010/05/25
19:41 UTC
Read the original article
Hit count: 139
JavaScript
|jQuery
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?
© Stack Overflow or respective owner