简体   繁体   English

Javascript页面总加载量

[英]Javascript Page Load Total

I've created a form that is used to calculate monthly expenses. 我创建了一个用于计算每月费用的表格。 The problem I'm having is on the last page I'm gathering information from previous pages (session to data) that auto fills the fields on the last page. 我遇到的问题是在最后一页上,我正在从前一页(会话到数据)收集信息,这些信息会自动填充最后一页上的字段。 I've created a javascript that is suppose to subtract the five fields on the page for a grand total but this doesn't work. 我创建了一个javascript,该javascript假定要减去页面上的五个字段以获得总计,但这是行不通的。 If I delete the session to data from the load section the javascript works perfectly. 如果我从加载部分删除到数据的会话,则javascript可以正常运行。

Page in Question: http://www.garranteedsolutions.com/budget?chronoform=BudgetPage7 有问题的页面: http : //www.garranteedsolutions.com/budget? chronoform= BudgetPage7

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) ;
}

This is the code that I had been using but it requires a change in the form box to perform the action. 这是我一直在使用的代码,但需要更改表单框才能执行操作。 I've tried this 我已经试过了

Javascript: Javascript:

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);
}

This is a continuation of me searching for help starting here: http://www.chronoengine.com/forums/viewtopic.php?f=2&t=67427&p=269741#p269741 这是我从此处开始寻求帮助的延续: http : //www.chronoengine.com/forums/viewtopic.php?f=2&t= 67427&p= 269741#p269741

I don't know Javascript very well and I'm so close to having this form completed. 我不太了解Java语言,因此我已经接近完成此表格。 I just can't get the Grand Total to tally up. 我只是无法总计总计。

The problem is that the events are only firing when you change the values of the form. 问题在于,仅当您更改表单的值时才会触发事件。 The form its readonly so they cannot be changed. 该表格为只读形式,因此无法更改。

Anyway, here is the code optimized: 无论如何,这是经过优化的代码:

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);
});

That should work. 那应该工作。 The function checks if the fields have value on them and if they have, they are included in the calculation. 该函数检查字段是否具有值,如果具有,则将其包括在计算中。

The second code you made fires the error because you are missing a parameter in the addEvent function. 您编写的第二个代码将引发错误,因为您缺少addEvent函数中的参数。

I hope that this can help you :) 我希望这可以对您有所帮助:)

This seemed to work! 这似乎有效! So now I'm trying to figure out how to get commas for the thousands. 因此,现在我试图弄清楚如何获得成千上万的逗号。 So if I input 1200 it displays 1,200. 因此,如果我输入1200,则显示1200。

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

Thank you so much for your help! 非常感谢你的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM