import wixData from “wix-data”;
import wixLocation from ‘wix-location’;
import wixWindow from ‘wix-window’;
import {local} from ‘wix-storage’;
let selected = 0;
let selectarray = [0,0,0,0,0,0,0,0,0];
$w.onReady( function () {
if (selected === 1) { $w(‘#text43’).text = “TRUE”;} /// <— This doesn’t work???
})
export function button1_click(event) {
if (selected < 3) {
if (selectarray[0] === 1) { selectarray[0] = 0; selected–; $w(“#button1”).label = “unclicked”; } else
{ selectarray[0] = 1; selected++; $w(“#button1”).label = “clicked”;
}
}
}
You assigned ‘selected’ the value of 0, then immediately created an if statement = to 1, how could text display the word ‘TRUE’ if you just told the variable to = 0?
Every time the page loads, selected will be set to 0 because you declare it every time as 0. You should store the selected value in a memory or session cookie. That’s if you want the clicked value to persist even if you refresh or leave and return to the page.
Setting your selectarray to this: [0,0,0,0,0,0,0,0,0] is the exact same as setting it to (an empty array) to the JS engine, as all your variables inside are falsy.
With that said, you’d be better off using a forEach statement. See:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
https://www.wix.com/corvid/example/collapse-elements
Btw I enjoy your videos!!! Doesn’t export function button1_click change ‘selected’?