Wondering if its possible to programatically update the state of a checkbox based on a button I pressed on a previous page. For example, observe the two navigation scenarios below…
Scenario A
- I enter on PAGE1
- I click a button ‘Los Angeles’
- I’m directed to PAGE2 with a checkbox ‘This Is LA’ selected
Scenario B
- I enter on PAGE1
- I click a button ‘San Francisco’
- I’m directed to PAGE2 with a checkbox ‘This Is LA’ that is DEselected
Hi Adam. You can do this with wix-storage. You need to add a line to include wix-storage after which in the function you call when clicking ‘Los Angeles’ you put a value into a wix-storage. See HERE . I do it all over my site with the ‘localstorage’. When you click my lanuage icon, the abbreviation is stored and I use that in my dataqueries to fetch the data in the right language.
When you do the part on page2, remember to put in a ‘default’ in case it fails, but that is more important if you use the technology for something else then setting a checkbox.
So:
- add import {local} from ‘wix-storage’; import {session} from ‘wix-storage’; (one of the two)
- local.setItem(“chkLA”, “Y”); in the function on page 1 for the LA button, and set it with “N” clicking a different button
- in the on ready add a part to set the checkbox to check if there is a store item (again add the import too) on page 2
...
// check if exists and is Y
if (local.getItem("chkLA") === "Y") {
$w("#chkLA").checked = true;
}
See if you can get further with this information.
Thanks Edgar Ill give this a shot!
I take it from this that the pages can’t communicate? Is there a reason?
I’m sure they can im just not certain how they should in code. I have a repeater connected to a dataset. I want the data set to automatically filter onReady based on buttons pressed on previous pages.