I’m stuck on a probably very simple coding part for my website.
What i wanted to do first was to replace text of a text box inside a repeater using coding.
I did great for this part.
There is my actual code:
$w.onReady( async function () { var today = new Date(); var birthdate = new Date($w(“#text21”).text); var msPerDay = 364 * 24 * 60 * 60 * 1000; var age = (today.getTime() - birthdate.getTime()) / msPerDay; var age = Math.round(age); $w(“#text20”).text = age.toString(); })
This code get the birthdate value inside text box #text21 and return it to age (number) in textbox #text20.
My problem is that my code take only the value of the first container and return the result in every other containers in the others textbox #text20.
I want that each container use the code for his “own data”
Thanks for the clue Yisrael! I took a look at this function yesterday but I don’t have any idea how to integrate my code to the onItemReady() function… Any idea how to start it? or any easy example? This is my first time coding a website using Java with Wix. Plus, I’m French so the tutorial isn’t easy to understand! Big thanks in advance!
Big thanks guys! After many try, I finally made it!
I used forEachItem instead and it worked!
$w.onReady( async function () { $w(“#repeater1”).forEachItem( ($item) => { var today = new Date(); var birthdate = new Date($item(“#text21”).text); var msPerDay = 364 * 24 * 60 * 60 * 1000; var age = (today.getTime() - birthdate.getTime()) / msPerDay; var age = Math.round(age); $item(“#text20”).text = age.toString(); }); })