我的oracle apex表格形式中有一列Amount
。我需要在输入数据时计算此列下所有字段的SUM
,并显示在表格形式下方的Display only
字段中。
我认为可以使用JavaScript
完成此操作,并在JavaScript
列的onchange
处调用Amount
。
但我不知道如何在我的oracle apex表格形式中计算SUM
列的Amount
。我怎么能这样做?
答案 0 :(得分:1)
将以下JavaScript
代码添加到Page 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();"