我正在使用gridview来计算行输入,但是我无法获得最后一行的值,例如假设我的网格视图中有6行,所以我的下面的代码在5行中运行正常但是没有考虑最后一行。
function HSACalculator(TotalContributionAmount, ddfequ) {
var taxPercent = 10;
var txtValue = 0;
var ddlValue = "";
var freq = 0;
var AnnualCost = 0;
var PerMonthPay = 0;
var MaxValuePerPay = 0;
var MaxValueAnnual = 0;
var grid = $(":asp(gvHSACalculator)")[0];
var cellPivot;
debugger;
if (grid.rows.length > 0) {
for (i = 1; i < grid.rows.length ; i++) {
cell = grid.rows[i].cells[1];
cellDDL = grid.rows[i].cells[2];
for (j = 0; j <= cell.childNodes.length; j++) {
if (cell.childNodes[j].type == "text") {
txtValue = cell.childNodes[j].value;
}
if (cellDDL.childNodes[j].type == "select-one") {
ddlValue = cellDDL.childNodes[j][cellDDL.childNodes[j].selectedIndex].value;
}
}
if (ddlValue != null) {
freq = getFrequencyValueNew(ddlValue);
AnnualCost = AnnualCost + freq * txtValue;
PerMonthPay = AnnualCost / 12;
}
}
var maxCont = document.getElementById("lblMaxContPerYear").innerHTML;
if (parseFloat(maxCont.replace("$", "").replace(",", "")) < parseFloat((Math.round(AnnualCost * 100) / 100))) {
alert("Annual Contribution can not be more than Max Contribution " + maxCont);
ddfreq = getFrequencyValue(ddfequ);
document.getElementById("lblDeductionPerPay").innerHTML = formatDollar(Math.round((AnnualCost / ddfreq) * 100) / 100);
document.getElementById("lblDeductionAnnual").innerHTML = formatDollar(Math.round(AnnualCost * 100) / 100);
document.getElementById("lblMaximumAnnual").innerHTML = formatDollar(Math.round(TotalContributionAmount * 100) / 100);
document.getElementById("lblTaxSavingPerPay").value = formatDollar((AnnualCost * taxPercent) / 100);
document.getElementById("lblTaxSavingAnnual").value = formatDollar((AnnualCost * taxPercent) / 100); // AnnualCost / 12;
}
else
{
ddfreq = getFrequencyValue(ddfequ);
document.getElementById("txtAnnualContribution").value = formatDollar(Math.round(AnnualCost * 100) / 100);
document.getElementById("txtActualPerDeduction").value = formatDollar(Math.round((AnnualCost / ddfreq) * 100) / 100);
document.getElementById("lblDeductionPerPay").innerHTML = formatDollar(Math.round((AnnualCost / ddfreq) * 100) / 100);
document.getElementById("lblDeductionAnnual").innerHTML = formatDollar(Math.round(AnnualCost * 100) / 100);
document.getElementById("lblMaximumAnnual").innerHTML = formatDollar(Math.round(TotalContributionAmount * 100) / 100);
document.getElementById("lblTaxSavingPerPay").innerHTML = formatDollar((AnnualCost * taxPercent) / 100);
document.getElementById("lblTaxSavingAnnual").innerHTML = formatDollar((AnnualCost * taxPercent) / 100); // AnnualCost / 12;
document.getElementById("lblMaxContPerYear").innerHTML = formatDollar(Math.round((TotalContributionAmount) * 100) / 100);
}`
}
return false;
}
答案 0 :(得分:0)
尝试
for (i = 1; i <= grid.rows.length ; i++)
答案 1 :(得分:0)
你可以试试下面的内容:
for (i = 0; i < grid.rows.length ; i++)
而不是上面使用的那个,因为网格视图行索引总是从0开始而不是1也设置'i'小于网格视图行的长度。