How to solve value error in switch button


i need help about velo
$w.onReady(function() {
$w(“#switch1”).onChange(function () {
if ($w(‘#switch1’).value) {
$w(“#box1”).show();
} else { $w(“#box1”).hide(); }

    let loc = $w("#switch1").value; 
    let cuis = $w("#box1").value; 

    local.setItem("switch1", loc); 
    local.setItem("box1", cuis); 
}) 

$w.onReady(() => { 
    let locat = local.getItem("switch1"); 
    let cuisin = local.getItem("box1"); 

    $w("#switch1").value = locat; 
    $w("#box1").value = cuisin; 

}); 

});

I have such a code but $w(“#switch1”).value = locat; It gives an error in this part (value) I also used the checked tag, the error is not fixed, please help.
If you’re asking where to use this: I have a switch button, when I click the button, the button pops up (it becomes active) and remains saved even if the page is refreshed. By the way, if you are asking how box1 accepted the value: I used input instead of box. I also renamed it to box1.

I don’t think you can nest one $w.onReady function inside another. All your code should be in a single onReady.


unfortunately the error is still not fixed

If “switch1” is type Switch then accoridng to the docs “value” shouldn’t be used https://www.wix.com/velo/reference/$w/switch/value

Instead you should use “checked” https://www.wix.com/velo/reference/$w/switch/checked

How do I fix the “locat” blurry place? The problem is not fully resolved