Good day, I am using the code below to add to a value depending on a result. I want a #text25 to change depedning on input on #text30 and/or #text31.
I start by defining #text25 as 0 (zero). Not sure if I am doing it ocrrectly and then adding +3 within an IF statement.
Please help. I do not get anything to display on #text25 in live website. It is not giving me an error which makes it harder to troubleshoot.
import wixUsers from 'wix-users'; import wixData from 'wix-data'; import wixLocation from 'wix-location'; import wixWindow from 'wix-window'; $w.onReady(function () { let score = 0 ; $w("#text25").type = score ; $w("#dynamicDataset").onReady( () => { $w("#repeater1").forEachItem( ($w, itemData, index) => { //Adding the points here if($w("#text30").text === "yes" || $w("#text30").text === "maybe"){ $w("#vectorImage1").show(); score = score + 3 } else { $w("#line9").show(); } $w("#text25").type = score ; if($w("#text31").text === "yes" || $w("#text31").text === "maybe"){ $w("#vectorImage2").show(); score = score + 3 } else { $w("#line10").show(); } $w("#text25").type = score ;
}) }) })
Hi, I m not trying to make the user add something/ I want to create a function that ADDS to a number IF a situation happens. What I am trying to figure out is HOW to add elements in code. Example:
let score = 5
if ($w("#text25").string === "Yes"){
score = score + 5
}
This way if answer is YES, then score = 10
Hi,
The onReady function runs when the page loads, the user can't interact with the page before, create an onClick or onChange event for the relevant elements to run the code after interaction from the user.
Check out the following article about events: https://support.wix.com/en/article/wix-code-how-to-react-to-user-actions-using-events.
Good luck :)
Or