Sum and Show DataBase

Hello everyone,:sweat_smile:

I’m a web designer and I don’t have a lot of programming knowledge.

I created a form where people respond with values

“On a scale of 0 to 10, do you feel good? 8”

At the end of the form, I would like to add some results of the questions and show them.

Question “A + B = 9” or “C + D = 3”

and show the sum of all question results on one page

I used this code , but when a new person signs up, their score does not appear.

As far as I know, it shows in the Sandbox and not live …

Can someone help me?:hushed:


data.js

export function FormularioNutra_afterQuery(item, context) {
item.Score1 = item.es1Ansiedade + item.es2Persistencia;
item.Score2 = item.al1Doce + item.al2Agua;
item.Score3 = item.sa1Cansaco + item.sa2Quedas;
item.Score4 = item.at1AtividadeSemanal + item.at2TipoDeAtividade;
item.Score5 = item.pesoAtual - item.pesoObjetivo;
item.Score6 = item.Score4 +  item.Score3 +  item.Score2 +  item.Score1;
return item;
}

page.wix

$w.onReady(function () {
$w("#dataset1").onReady(() => {
populateCalculatedFields();
} );

$w("#dataset1").onCurrentIndexChanged( (index) => {
populateCalculatedFields();
} );
} );
function populateCalculatedFields() {
const currentItem = $w("#dataset1").getCurrentItem();
$w("#ESTotal").text = "" + currentItem.Score1;
$w("#ASTotal").text = "" + currentItem.Score2;
$w("#SGTotal").text = "" + currentItem.Score3;
$w("#ATTotal").text = "" + currentItem.Score4;
$w("#IPTotal").text = "" + currentItem.Score5;
$w("#Total").text = "" + currentItem.Score6;

}

Have you simply just tried using the code example given from Liran on hat linked page and does it work for you?

It also looks like you are trying to combine code from here as well.
https://support.wix.com/en/article/corvid-tutorial-calculating-and-displaying-collection-data

There are other ways of doing this like as in this previous forum post.
https://www.wix.com/corvid/forum/community-discussion/multiple-choice-quiz

Also, when you mention that it works in sandbox and not in live, then note that once the user is signed up to your site they will be using the Wix Users API which only fully works in a live published site and not in preview mode.

In Wix Editor you are working in the sandbox version, whereas the live site is using the live version of the dataset.
https://support.wix.com/en/article/syncing-data-between-sandbox-and-live-database-collections