Hello, I have a drop down menu on a page that is already setup to link to another page when something is selected. I would like for the selection to go to the correct page, and then change the state of the multistate box on that page.
$w("#hou100dropdown").options = [
{ "label": "101 | What is a Mortgage?", "value": "/101" },
{ "label": "102 | Downpayments Explained", "value": "/101#02" },
{ "label": "103 | Credit Scores", "value": "/101#03" },
];
export function hou100dropdown_change(event) {
let gotoUrl = $w("#hou100dropdown").value;
wixLocation.to(gotoUrl);
}
When I select an option in the drop down menu, it automatically goes to the page /101, but I would like for it to change the state as well. Is this possbile?
Thank you.
All you have to do is....
1) Save your value to the wix-storage before you leave your current page (like Anthony already mentioned the "Session-storage". The same way you could also use "local" instead.
2) Then you navigate relaxed to the next page.
3) On the following page you just have to load the value ($w.onLoad) from the wix storage, which you have saved before.
Et voilà! You have changed the page and you have still your value.
Where you specify "state", is that the name of the state on the multistate box?
So if my states are all labeled 01, 02, 03, etc then the code should be
import {session} from 'wix-storage'; export function hou100dropdown_change(event) { session.setItem("01", $w("#hou100dropdown").label); let gotoUrl = $w("#hou100dropdown").value; wixLocation.to(gotoUrl); }
am I following you correctly? Thank you!
@dane.anar You could utilize the wix-storage API to store the state in the page with the dropdown, and then in the onReady of the page with the multistate box, apply the state. If the label of the dropdown is the actual name of the state on the other page, it would go like this:
import {session} from 'wix-storage'; export function hou100dropdown_change(event) { session.setItem("state", $w("#hou100dropdown").label); let gotoUrl = $w("#hou100dropdown").value; wixLocation.to(gotoUrl); }
Then on the page with the multistate box:
import {session} from 'wix-storage'; $w.onReady(function () { let state = session.getItem("state"); $w("#statebox").changeState(state); });