I am creating a website with a summary container box. On the container box, I would like to summarize a customer order according to the service they wanted.
One of the inputs is selection tags that connect to a repeater, showing name and price.
Now, When I try to add the value of the repeater using the code below, it doubles or triple the price of the item
function setRepeatedItemsInRepeater() { var tagConcat; const selectedTags = $w('#selectionTags1').value; let nr = selectedTags.length; let sum = 0; $w('#repeater1').onItemReady(($item, itemData) => { $item('#extraSvcTitle').text = itemData.shortName; $item('#extraCSvcPrice').text = String(parseFloat(itemData.price).toFixed(2)); for(var i = 0; i <= nr; i ++) { sum += parseFloat(itemData.price); $w('#text190').text = String(sum); // here is the big text file in the screenshot } }) }
let dataQuery = wixData.query(collectionName); if (selectedCategories.length > 0) { dataQuery = dataQuery.hasSome(fieldToFilterByInCollection,selectedCategories); } dataQuery .find() .then(results => { // const cnt = results.totalCount; const itemsReadyForRepeater = results.items; $w('#repeater1').data = itemsReadyForRepeater; const isRepeaterEmpty = itemsReadyForRepeater.length === 0 // $w('#text191').text = String(cnt); }) } $w('#selectionTags1').onChange((event) => { $w("#repeater1").show(); const selectedTags = $w('#selectionTags1').value; if (selectedTags.length === 0) { $w("#repeater1").hide(); } else { loadDatatoRepeater(selectedTags); setRepeatedItemsInRepeater(); } }) });
![](https://static.wixstatic.com/media/a27d24_584d7373626a4bb4974e23827fb73083~mv2.png/v1/fill/w_54,h_68,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/a27d24_584d7373626a4bb4974e23827fb73083~mv2.png)
I concatenated the price in a string and saw that it is indeed double and sometimes tripled (more than) (ignore the undefined it's just a variable I didn't define).
Can someone help? Thanks!
![](https://static.wixstatic.com/media/a27d24_bbce73aee61d4da681e9c65a2c0b18ef~mv2.png/v1/fill/w_78,h_62,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/a27d24_bbce73aee61d4da681e9c65a2c0b18ef~mv2.png)
Hello and happy new year!
I think this is the code-part which makes problems.
for(var i = 0; i <= nr; i ++) { sum += parseFloat(itemData.price); $w('#text190').text = String(sum); // here is the big text file in the screenshot }
You have several selected TAGs which you define in a variable called (nr)
let nr = selectedTags.length;
nr = the length of your TAG-selections. So if you have 2 or 3 selected TAGs, then you will get also the same amount of loops in your for-loop.
This doubles or triples your SUM.
But what you want is to get the right price out of the current selected TAG, right? You should tryy something like...
for(var i = 0; i <= nr; i ++) { sum += parseFloat(itemData[i].price); $w('#text190').text = String(sum); }
or
for(var i = 0; i <= nr; i ++) { sum += parseFloat(itemData.price[i]); $w('#text190').text = String(sum); }