# Velo Code Help - Buttons with Multi State box

**URL:** <https://forum.wixstudio.com/t/velo-code-help-buttons-with-multi-state-box/57389>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [March 20, 2024, 7:37pm UTC](https://forum.wixstudio.com/t/velo-code-help-buttons-with-multi-state-box/57389 "2024-03-20T19:37:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asif\_Zaman](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/asif_zaman/32/89915_2.png) [@Asif\_Zaman](https://forum.wixstudio.com/u/Asif_Zaman)\
**Post date:** [March 20, 2024, 7:37pm UTC](https://forum.wixstudio.com/t/velo-code-help-buttons-with-multi-state-box/57389/1 "2024-03-20T19:37:11Z")

</div>

**Question:**  
Hi, I am trying to use a multi state box with 4 buttons which changes the box’s state, however my code doesnt seem to be changing the box upon clicking a button. I have included my code below, any help would be appreciated alot 🙂

$w.onReady(function () {  
button1\_click()  
});

export function button1\_click(event) {  
$w(“#statebox8”).changeState(“State1”);  
}

export function button2\_click(event) {  
$w(“#statebox8”).changeState(“State2”);  
}

export function button3\_click(event) {  
$w(“#statebox8”).changeState(“State3”);  
}

export function button4\_click(event) {  
$w(“#statebox8”).changeState(“State4”);  
}

const blackColor = “#000000”;  
const greyColor = “#C7C7C7”;

export function statebox8\_change(event) {  
const buttonNames = $w(“#columnStrip5”).children.filter((elem) =\> { return elem.id.includes(“button”) }).map((f) =\> { return f.id}); //[1,2,3,4]

```
buttonNames.map((name, index) => {

```

let button = $w(`#${name}`); // e.g. $w(“#button1”)  
let length = index+1;  
let state = “State”+length; // e.g. State1  
[//console.log](https://console.log)(state);  
if (event.target.currentState.id === state) {  
button.style.backgroundColor = blackColor;  
} else {  
button.style.backgroundColor = greyColor;  
}  
})  
}

---

<div class="post-metadata">

**Author:** ![codequeen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/codequeen/32/88960_2.png) [@codequeen](https://forum.wixstudio.com/u/codequeen)\
**Post date:** [March 20, 2024, 8:01pm UTC](https://forum.wixstudio.com/t/velo-code-help-buttons-with-multi-state-box/57389/2 "2024-03-20T20:01:49Z")

</div>

Did you copy and paste this code from somewhere? Or did you actually use the code event’s panel to set the onClick event?

---

<div class="post-metadata">

**Author:** ![Asif\_Zaman](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/asif_zaman/32/89915_2.png) [@Asif\_Zaman](https://forum.wixstudio.com/u/Asif_Zaman)\
**Post date:** [March 20, 2024, 9:59pm UTC](https://forum.wixstudio.com/t/velo-code-help-buttons-with-multi-state-box/57389/3 "2024-03-20T21:59:55Z")

</div>

Hi,

I used the code from a tutorial video and made a few changes to it.

Many thanks,  
Salim

---

<div class="post-metadata">

**Author:** ![Asif\_Zaman](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/asif_zaman/32/89915_2.png) [@Asif\_Zaman](https://forum.wixstudio.com/u/Asif_Zaman)\
**Post date:** [March 20, 2024, 10:49pm UTC](https://forum.wixstudio.com/t/velo-code-help-buttons-with-multi-state-box/57389/4 "2024-03-20T22:49:09Z")

</div>

Hi,

I managed to fix my code. Thank you for reaching out 🙂

Best,  
Salim
