Sum Multiple Fields

@jonatandor35 All the values are stored on WIX DB, J1…J5 are fields that the Judge entered in other page, in this page i need to show the sum of the values of the judgments on the text attached is the print screen of the score board, so the 0 in after puntaje total is #PT and bellow is the J1…J5 that each contender get from each judge

@ricardorosenblatt if the values are set in other pages, why are you using user inputs here and not just textboxes?
Anyway, it doesn’t make sense to use $w("#PT).onViewportEnter(). becuse PT may enter to the viewport before the user inputs get populated and therefore it’ll set to zero.

So setting the PT highly depends on how you populate the user inputs (it deferment if you connect a dataset via the editor, or retrieve the info from the memory or browser cache etc…)
Also if it’s a repeater the code should be adjusted to repeater items.

@jonatandor35 Yes is on a repeater, and i get from the Dataset

@ricardorosenblatt so you’ll need to make the calculation in a repeater onItemReady() function (and not onViewportEnter):
https://www.wix.com/corvid/reference/$w.Repeater.html#onItemReady
Don’t forget to use $item instead of $w.

@jonatandor35 Ok thanks i will try to do, is some hard to me!! i thought where more simple like and SQL statement do WIX have no Filed with calculated field is harder for a non programmer.

@J. D. I use the onItemReady but it’s give me the sum 0
$w.onReady ( function () {
const inputs = [$w(“#J1”), $w(“#J2”), $w(“#J3”),$w(“#J4”),$w(“#J5”)];
$w(“#repeater1”).onItemReady ( ($item,) => {
let rrepeatedElement = $item(“#PT”);
let sum = 0;
inputs.forEach(i => {
if ( typeof i.value !== “undefined”){sum += Number(i.value);}
})
$w(“#PT”).text = sum.toString();
})
})

@ricardorosenblatt

$w.onReady (function  () {
$w("#repeater1").onItemReady ( ($item, $itemData, index) => {
    let inputs  = [$item("#J1"), $item("#J2"), /*etc..*/];
    let sum = 0;
    inputs.forEach(i => {
        if (typeof i.value !== "undefined"){sum += Number(i.value);}
    })
    $item("#PT").text = sum.toString();
    })
})

@jonatandor35 Thanks!!! but still #PT give me 0 sorry :frowning:

@ricardorosenblatt I don’t see the PT in your screenshot above. You’re probably doing something wrong, like using the wrong property id, or using a user input for PT instead of textbox or not having the PT inside the repeater. I don’t know.

@jonatandor35 PT is the text that is 0 after the text puntaje total, in the screen shot I shone the value of PT that is 0

@ricardorosenblatt So I don’t know. Last idea: you’re using textboxes for all the J’s and not user inputs.

@jonatandor35 Nope they are usr inputs, with numeric format

@ricardorosenblatt so I ran out of ideas. You’ll need to play with it, to test some slightly different directions, to use console.log and try to locate the problem. It’s not something that can be done remotely.

@jonatandor35 Perfect, thank you!! if i make it run i will post you!