Change multi state box from header

Hello guys,

I need so help.

I have added buttons on header, where I need to switch not only page but also multi state box on the page.

The issue is that, I page is changing of but multi state box not. However when I al clicking second time multi state box works.

I need to change page and after multi state box with onClick event from header.

Here is the link and the code.

https://amiranazaladze.wixsite.com/my-site-16

//-----header/master page code
import wixLocation from ‘wix-location’ ;

export function button1_click ( event ) {
wixLocation . to ( “/page-1” ) ;
$w ( “#statebox1” ). changeState ( " stateForbutton" );
}
//--------------------------------------------

Thank in advance

#multistatebox #statebox #masterPage #changeState

You can try the following:

(I haven’t tried it so it may not work, Please let me know)

export function button1_click(event) {
Promise.all([
    wixLocation.to('/page-1') ,
    $w('#statebox1').changeState('stateForbutton')
]);
}

If that doesn’t work, you can do:

master page code:

import wixLocation from 'wix-location';
export function button1_click(event) {
    wixLocation.to('/page-1?state=stateForbutton');
}

page-1 code:

import wixLocation from 'wix-location';
$w.onReady(() => {
	if(wixLocation.query?.state === 'stateForbutton'){
	$w('#statebox1').changeState('stateForbutton');
	}
})

Thank you so much! code second version worked well. Perfect.

Sorry for the delayed reply. I was in Ukraine, Kharkiv and needed to change my location

@amiranazaladze You’re welcome. Are you OK now?