简体   繁体   中英

Need a simple numerical value difference(+/-) script for different occasions on the same web page

I authored a web page/form utilizing a chart script(AMcharts) which involves inputs of many numerical values in order to make a graph. Built into this web page is a separate average script utilized many times in order to get many successive average values, as well as a simple numerical difference script for the last two/three of the final average values. Basically, when all averages are parsed, a value from a previous occasion is typed in an input field, and the script instantly displays a difference, either + or -. The average value script I managed to manipulate for 16 occasions (much to my surprise). I am, however, having problems manipulating the numerical difference script in order to display more than one value difference set. The simple script found below is utilized successfully, however I need to know how to manipulate it for more than just that one occasion.

$(function(){           
    $('input').each(function() {
        $(this).keyup(function(){  
            calculateTotal($(this));
        });
    });
});

function calculateTotal(src) {
    var sum = 0;
    var sumtable = src.closest('.sumtable');

    sumtable.find('input').each(function() {
        if(!isNaN(this.value) && this.value.length!=0) {
            sum += parseFloat(this.value);
        }
    });

    sumtable.find(".total").html(sum.toFixed(2));
    var balance = parseFloat($('.actual').val()) - sum
    sumtable.find(".balance").html(balance.toFixed(2));
}  

I need the following code repeated for different value fields, independent of the other(s):

http://jsfiddle.net/ZZX5D/

The following link takes you to my work in progress. To make it work(not the graph, but the numerical scripts), type in random values for the first four empty fields- B1 PS/CS - B2 PS/CS and under "battery 2" fill in the first 4 empty fields. Then in the above averaged displays, simply click inside all fields with a numerical value and press "enter", and continue doing so until all fields are automatically displayed. Then, under "previous" fields, type another random number. The first field "difference" is correct. The remaining two display the difference between that number and the initial "overall" instead of the last average values to their immediate left.

http://dcalvitti.altervista.org/AVGSAMPLE.html

Never solved this, but found an alternate script that was easy to manipulate and thus serve my purposes.

http://www.codingfriends.com/index.php/2009/07/27/add-two-numbers-3/

And the chart incorporating this solution can be found at this page:

http://dcalvitti.webs.com/SAMPLE/NEWWEBINDEX.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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