Hi everyone!
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"
Anyone can help me with that?
coding:
result:
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();
});
})
You need to implement an onItemReady() function for your Repeater. See the Repeater API for more information on using Repeaters.