# Code works on preview, but not on live site preview

**URL:** <https://forum.wixstudio.com/t/code-works-on-preview-but-not-on-live-site-preview/48805>\
**Category:** Ask the community\
**Created:** [August 5, 2022, 8:42am UTC](https://forum.wixstudio.com/t/code-works-on-preview-but-not-on-live-site-preview/48805 "2022-08-05T08:42:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahlalalalala](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shahlalalalala/32/8489_2.png) [@shahlalalalala](https://forum.wixstudio.com/u/shahlalalalala)\
**Post date:** [August 5, 2022, 8:42am UTC](https://forum.wixstudio.com/t/code-works-on-preview-but-not-on-live-site-preview/48805/1 "2022-08-05T08:42:06Z")

</div>

So first of all I’d like to clarify that I’m a novice at coding- I’m a designer, not a coder.

I wrote some code to change the state of a Multi-State Box when certain text is clicked on, and since that text is duplicated across all the states, I put those elements into an array so I didn’t have to call the onClick function for them individually.

The site is not live yet, so I’m only checking it through the Site Preview option and it’s throwing up a bunch of errors that my small, non-coder brain cannot comprehend. There are no errors in Preview mode from the editor.

This is the code, please forgive its messiness:

```javascript
$w.onReady(function () {
switchOnClick();
}); 

const econ = $w("#econTextP, #econTextC, #econTextT, #econtextL, #econTextD");
const politics = $w("#politicsTextE, #politicsTextC, #politicsTextT, #politicsTextL, #politicsTextD");
const climate = $w("#climateTextE, #climateTextP, #climateTextT, #climateTextL, #climateTextD");
const tech = $w("#techTextE, #techTextP, #techTextC, #techTextL, #techTextD");
const life = $w("#lifeTextE, #lifeTextP, #lifeTextC, #lifeTextT, #lifeTextD");
const edu = $w("#eduTextE, #eduTextP, #eduTextC, #eduTextT, #eduTextL");

function switchToRelevant(state) {
    $w('#multiStateBoxArticles').changeState(state);
}

function switchOnClick() {
    econ.onClick(() => {
        switchToRelevant('econState')
    })

    politics.onClick(() => {
        switchToRelevant('politicsState')
    })

    climate.onClick(() => {
        switchToRelevant('climateState')
    })

    tech.onClick(() => {
        switchToRelevant('techState')
    })

    life.onClick(() => {
        switchToRelevant('lifeState')
    })

    edu.onClick(() => {
        switchToRelevant('eduState')
    })
}

```

---

<div class="post-metadata">

**Author:** ![AndrewT](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/andrewt/32/32103_2.png) [@AndrewT](https://forum.wixstudio.com/u/AndrewT)\
**Post date:** [August 10, 2022, 6:21am UTC](https://forum.wixstudio.com/t/code-works-on-preview-but-not-on-live-site-preview/48805/2 "2022-08-10T06:21:14Z")

</div>

hey, @shahlalalalala if the issue is not resolved yet, please contact our Velo team, you can find instructions here: [https://support.wix.com/en/article/contacting-wix-customer-care-for-support](https://support.wix.com/en/article/contacting-wix-customer-care-for-support)  
once you will launch the ChatBot please type Velo inside the input field

---

<div class="post-metadata">

**Author:** ![shahlalalalala](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shahlalalalala/32/8489_2.png) [@shahlalalalala](https://forum.wixstudio.com/u/shahlalalalala)\
**Post date:** [August 10, 2022, 7:30am UTC](https://forum.wixstudio.com/t/code-works-on-preview-but-not-on-live-site-preview/48805/3 "2022-08-10T07:30:05Z")

</div>

Hi Andrew, modifying the code to call the function for each item individually fixed it. I’m still baffled on why it worked on the preview and not the live, though.
