In my dynamic form I need to calculate data from from 3 fields(qty,rate,discount) and pass it to unitdiscount. The formula will be - unitdiscount = ((qty*rate*discount)/10
Try this way :
function getUdisc(item) {
var index = item.attr("id").replace(/[^0-9.]/g, "");
var total = current = next = previous = 0;
var id = item.attr("id");
var myString = id.split("-").pop();
if (myString == "qty") {
fetch1 = index.concat("-discount");
fetch2 = index.concat("-rate");
} else if (myString == "discount") {
fetch1 = index.concat("-qty");
fetch2 = index.concat("-rate");
} else {
fetch1 = index.concat("-discount");
fetch2 = index.concat("-qty");
}
temp1 = $("#productsales-"+fetch1+"").val();
temp2 = $("#productsales-"+fetch2+"").val();
if (!isNaN(temp1) && temp1.length != 0) {
next = temp1;
}
if (isNaN(temp2) || temp2.length == 0) {
previous = temp2;
}
current = item.val();
if (isNaN(current) || current.length == 0) {
current = 0;
}
if (!isNaN(current) && !isNaN(next) && !isNaN(previous)) {
total = (parseFloat(current) + parseFloat(next) + parseFloat(previous)).toFixed(2);
}
udiscField = "productsales-".concat(index).concat("-udisc");
$("#"+udiscField+"").val(total);
}