Filter and display results on another page

Hey,
I want to set a filter on the homepage and show the results on another page.
Here’s a code from the forum:

Homepage:

import {local} from 'wix-storage';
import wixLocation from 'wix-location';
 
export function searchButton_click() {

 let word = $w("#searchBar").value;
    local.setItem("searchWord", word);
    wixLocation.to(`/results`); 
}

Page:

import {local} from 'wix-storage';
import wixData from 'wix-data';

$w.onReady(function () {

 var sameWord = local.getItem("searchWord");

    $w("#searchBar").value = sameWord;
    $w("#searchBar").placeholder = sameWord;
    $w('#nameDataset').onReady(function () {
        search();
    });
});

export function searchButton_click() {
    search();
}
 
function search() {
    wixData.query('Name')
   .contains('name', $w("#searchBar").value)
   .or(wixData.query('Name').eq('number', $w("#searchBar").value))
      .find()
       .then(res => {
  $w('#repeater1').data = res.items;
    });
}

How do I make this for individual checkboxes ? I have no value here. So I have to check if the checkbox is checked and set the checkbox on the new page checked.

But what’s the right code for this ?

Hey Nick,

As you said you cannot use the value property to determine if a checkbox is checked or not. You must use the checked property.

You can learn more about this by reading our Checkbox API.

I hope this helps!

Dara | Corvid Team

Hey,
not really. I tried some code, but I don’t get it.

Homepage code:

export function Search_click(event) {

 let abc = $w("#checkbox1").value;

 if ($w("#checkbox1").checked === true) { local.setItem("Value", abc);
 }
    wixLocation.to(`/filter`);
}

Page code:

import { local } from 'wix-storage';

$w.onReady(function () {

 var abc = local.getItem("Value");

 if ($w("#checkbox1").value === abc) {
        $w("#checkbox1").checked = true;
    }
}

checkbox1 has the value “Value” at the filterpage.

I tried to code something like:

Homepage:
If checkbox1 is checked, set the value “Value” then locate to /filter

Filterpage:
If checkbox1 has the same value as local.getItem, check checkbox1.

But the code always check checkbox1.

ok, I found a solution

Well done Nick! That’s the way you learn :wink:. Learning by doing :grin:

1 Like