Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript JavaScript: Adding a Function to Calculate the Sum of Product Quantities in Orders

filipix

New Coder
Hello everyone!

I inherited an open-source program from an independent developer that manages receipts for local festivals. Among the various options, there is the so-called "digital order." Essentially, the receipts are sent from the computer to the local network, and through a web platform based on JavaScript and a website with CSS styles, the order is displayed in various departments.

I have a problem. I would like to insert a function into the JavaScript code that sounds simple to say but I find it difficult to implement: I want the SUM of the quantities of each product in the active orders to be displayed at the top of the page. Once I make the order disappear with the appropriate button, it is obviously canceled.

I'm attaching an image of the interface, and below I'm posting the part of the code that, from my limited knowledge, I believe is related to the part I want to modify.

Thanks to anyone willing to help me with this endeavor!

JavaScript:
var lastLoad;
var orderK;
var tmrAnn;

$(document)
    .ready(function () {
        $('input[type="checkbox"]')
            .click(function () {
                if ($(this).prop("checked"))
                    {
                        $.post("/null", 'act=a_prstse&idticketl=' + $(this).attr('value'));
                        $(this).closest("tr").find(".cassa-sts-blue").removeClass("cassa-sts-blue").addClass("cassa-sts-green");
                        $(this).closest("tr").find(".fa-clock-o").removeClass("fa-clock-o").addClass("fa-check");
                    }
                else
                    {
                        $.post("/null", 'act=a_prstsp&idticketl=' + $(this).attr('value'));
                        $(this).closest("tr").find(".cassa-sts-green").removeClass("cassa-sts-green").addClass("cassa-sts-blue");
                        $(this).closest("tr").find(".fa-check").removeClass("fa-check").addClass("fa-clock-o");
                    }
            });
            
        lastLoad = $('#timestamp').attr('value');
        orderK = $('#orderk').attr('value');
        getAlert();
    });

function getAlert() {
    clearInterval(tmrAnn);
    //if (orderK.length > 0) {
        $.get("/orderka.html", {timestamp: lastLoad, orderknr: orderK, now: $.now()}).done(function (data) {
            if (data.indexOf("true") > -1) {location.reload(true);}
        });
        tmrAnn = setInterval(getAlert, 7000);
    //}
}

function reload() {
    location.reload(true);
}

function getInput(name, id, page) {
    var key = '#' + id + ' input[type=text]';
    var page = '/' + page;
    var allData = '';
    $(key).each(function () {
        allData += '&' + $(this).attr('name') + '=' + $(this).val();
    });   
    data = 'act=' + name + '&id=' + id + allData;
    $.post(page, data);
    return false;
}
    
function blinker () {
    $('.blink_me').fadeOut(700).fadeIn(700);
}

setInterval(blinker, 2500);
 

New Threads

Buy us a coffee!

Back
Top Bottom