Javascript页面加载总量

Javascript页面加载总量,javascript,javascript-events,joomla,Javascript,Javascript Events,Joomla,我创建了一个用于计算每月费用的表单。我遇到的问题是在最后一页上,我正在从以前的页面(会话到数据)收集信息,这些信息会自动填充最后一页上的字段。我已经创建了一个javascript,假设它减去页面上的五个字段,得到一个总数,但这不起作用。如果我从load部分删除session to data,javascript就可以完美地工作 有关页面: Javascript: window.addEvent('domready', function() { $('spendable').addEvent

我创建了一个用于计算每月费用的表单。我遇到的问题是在最后一页上,我正在从以前的页面(会话到数据)收集信息,这些信息会自动填充最后一页上的字段。我已经创建了一个javascript,假设它减去页面上的五个字段,得到一个总数,但这不起作用。如果我从load部分删除session to data,javascript就可以完美地工作

有关页面:

Javascript:

 window.addEvent('domready', function() {
 $('spendable').addEvent('change', rekenen1);
 $('housetotal').addEvent('change', rekenen1);
 $('cartotal').addEvent('change', rekenen1);
 $('creditortotal').addEvent('change', rekenen1);
 $('misctotal').addEvent('change', rekenen1);
});
function rekenen1(){
$('grandtotal').value = Number($('spendable').value) + Number($('housetotal').value) +   Number($('cartotal').value) + Number($('creditortotal').value) + Number($('misctotal').value) ;
}
window.addEvent('domready', function() {
rekenen1;
 $('spendable').addEvent(rekenen1);
 $('housetotal').addEvent(rekenen1);
 $('cartotal').addEvent(rekenen1);
 $('creditortotal').addEvent(rekenen1);
 $('misctotal').addEvent(rekenen1);
 });
 function rekenen1(){
 $('grandtotal').value = 
Number($('spendable').value) + Number($('housetotal').value) 
+ Number($('cartotal').value) + Number($('creditortotal').value) 
+ Number($('misctotal').value);
}
这是我一直在使用的代码,但它需要在表单框中进行更改才能执行该操作。我试过这个

Javascript:

 window.addEvent('domready', function() {
 $('spendable').addEvent('change', rekenen1);
 $('housetotal').addEvent('change', rekenen1);
 $('cartotal').addEvent('change', rekenen1);
 $('creditortotal').addEvent('change', rekenen1);
 $('misctotal').addEvent('change', rekenen1);
});
function rekenen1(){
$('grandtotal').value = Number($('spendable').value) + Number($('housetotal').value) +   Number($('cartotal').value) + Number($('creditortotal').value) + Number($('misctotal').value) ;
}
window.addEvent('domready', function() {
rekenen1;
 $('spendable').addEvent(rekenen1);
 $('housetotal').addEvent(rekenen1);
 $('cartotal').addEvent(rekenen1);
 $('creditortotal').addEvent(rekenen1);
 $('misctotal').addEvent(rekenen1);
 });
 function rekenen1(){
 $('grandtotal').value = 
Number($('spendable').value) + Number($('housetotal').value) 
+ Number($('cartotal').value) + Number($('creditortotal').value) 
+ Number($('misctotal').value);
}
这是我搜索帮助的继续,从这里开始:


我不太懂Javascript,我很快就要完成这个表单了。我就是不能把总数加起来。

问题是,只有当您更改表单的值时,事件才会触发。表单为只读,因此无法更改

无论如何,下面是优化的代码:

window.addEvent('domready', function() {
    var rekenen1 = function(){
        var grandTotal = 0;
        $$('#spendable, #housetotal, #cartotal, #creditortotal, #misctotal').each(function(el){
            if(el.value.length > 0) grandTotal += el.value.toFloat();
        });
        $('grandtotal').value = grandTotal;
    };
    $$('#spendable, #housetotal, #cartotal, #creditortotal, #misctotal').addEvent('onchange', refenen1);
});
这应该行得通。该函数检查字段是否有值,如果有值,则将其包括在计算中

由于addEvent函数中缺少一个参数,因此所生成的第二个代码将触发错误


我希望这能帮助你:)

这似乎奏效了!所以现在我想知道如何为成千上万的人得到逗号。所以如果我输入1200,它会显示1200

window.addEvent('domready', function() {
$('grandtotal').value = Number($('spendable').value) + Number($('housetotal').value) + Number($('cartotal').value) + Number($('creditortotal').value) + Number($('misctotal').value);
});

非常感谢你的帮助

这不管用。控制台显示以下内容:
Uncaught ReferenceError:refenen1未定义rokboxPathbudget:76(匿名函数)mootools core.js:370 hmootools core.js:33 Array.implement.eachmootools core.js:39 invoke.fireventmootools core.js:369 g
是否需要取消只读?我真的很想打开它,这样最终用户就不能更改总数。这个函数名为rekenen1而不是refenen1。我想你把名字拼错了