2013-01-22 69 views
0

我的oracle apex表格格式中有一列为Amount。当输入数据时,我需要计算此列下所有字段的SUM,并在表格下方的Display only字段中显示。计算Oracle Apex表格格式单元格的总和

,我认为这可以使用JavaScript完成并调用JavaScriptAmountonchange

但我不知道如何计算AmountSUM列在我的oracle apex表格形式。我怎么能这样做?

回答

1

添加以下代码JavaScript到页HTML Header属性:

<script type="text/javascript"> 
function tot_cal() 
{ 
var f5=new Array(); 
var tol=0; 
f5=document.getElementsByName("f05"); /*f05 is Apex array which holds the data*/ 

for(i=0;i<f5.length;i++){ 
    tol = (tol*1) + (f5[i].value.replace(/,/g, '') * 1); 
} 
/* alert(tol); */ 
$s('P10_AMOUNT_VALUE', tol.formatMoney(2,',','.')); 
} 
Number.prototype.formatMoney = function(decPlaces, thouSeparator, decSeparator) { 
    var n = this, 
    decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces, 
    decSeparator = decSeparator == undefined ? "." : decSeparator, 
    thouSeparator = thouSeparator == undefined ? "," : thouSeparator, 
    sign = n < 0 ? "-" : "", 
    i = parseInt(n = Math.abs(+n || 0).toFixed(decPlaces)) + "", 
    j = (j = i.length) > 3 ? j % 3 : 0; 
    return sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator) + (decPlaces ? decSeparator + Math.abs(n - i).toFixed(decPlaces).slice(2) : ""); 
}; 
</script> 

表格形式元素/元素属性Amount列的属性:

onchange="tot_cal();"