export function checkbox1_change(event) {
if ($w("#checkbox1").checked) {
$w("#textDescription").text = "This is text sent here after checking #checkbox1";
}
else
$w("#textDescription").text = "";
}
Additional to yvervoort suggestion, another possibility (should be improved a little bit to get a perfect result).
$w('Checkbox').onChange((event)=>{
let selectedElement = event.target.id
for (var i = 0; i < PutInHereTheLengthOfCheckboxes; i++) {
switch(selectedElement)){
case ("checkbox"+i):
$w("#textDescription").text = "This is text sent here after checking
break;
}
}
})
Thank you all very much for your time replying to my post. All these approaches are very effective and clever. I don’t know though, how would you deal with the fact that each and every checkbox is related to a different .text… So cb1, when checked, displays text1, cb2–>text2, … cb29–>text29.
myArray = []
myArray.push()
// make it so, that you have this at the end.....
myArray = ["text1", "text2", "text3"] //---< and so on.....
console.log(myArray[0])
console.log(myArray[1])
console.log(myArray[2])
// + ---> loop
In my example, i already gave you the idea with the loop.
let myText1 = "Here is my first text, whatever it is, i don't know"
let myText2 ="Here will be my second one"
let myText3 = "And here we will have the third text-example"
myArray = [myText1, myText2, myText3]
@gemats depending on how far you want to go with this, I’d suggest to work with an intermediate object which contains the data to populate your UI components.
You can either choose to manually add the data to the object in your application layer, but getting it from the database is also an option.
var nbItems = 29; //get from db
var cb = {
"label": "",
"description": ""
}
var obj = [];
for(i=0;i<nbItems;i++){
cb.label = db[i].label;
cb.description = db[i].description;
obj.push(cb);
}
console.log(obj);
//populate UI elements