Search button that connects to my Data Collection.

I want to put a search bar in my header and when a client searches a particular item, it will go to a dynamic page that has the item information the the client search.

This can be done using Wixcode.
Get the value the user entered in the search bar using:

let searchValue = $w("#searchBar").value;

Then, redirect the user to the right dynamic page using:

wixLocation.to("/[dynamic-page-name]/[field-name]/" + searchValue");

Good Luck!

Hi Ohad, Thank you for help.
Can you hand me some working codes on this one? I’m not really good at coding. Thank you in advance Ohad!

Hi,
You can create onClick event for the search button(check out this video) and then modify the following code to match your element’s names.

$w("#myElement").onClick( (event, $w) => {
  let searchValue = $w("#searchBar").value;
  wixLocation.to("/[dynamic-page-name]/[field-name]/" + searchValue");
} );

Also check out the wix-location’s API.
Good luck

Hi Or,
Good day, thank you for helping me on this, much appreciated. one question.

 wixLocation.to("/[dynamic-page-name]/[field-name]/" + searchValue"); 
 
 I don't get the [field-name]. where can I get it or find it?

Hi Geovel,
You can find it here:

Roi

Hi Roi, Ohad and OR,

I don’t know if I doing it right. It doesn’t working on me.

$w("#button6").onClick( (event, $w) => {
  let searchValue = $w("#input12").value;
  wixLocation.to("/profile/{ID}" + searchValue);
} );

Please advice. Thank You!

Here’s the link to my editor - https://editor.wix.com/html/editor/web/renderer/edit/0f2a2a2e-c0ef-4f72-98b3-679302cef3fb?metaSiteId=a6fdb801-9819-4822-8a0c-9d8fd99355b4&editorSessionId=CFBBB3D0-C121-41C3-9B38-DC2D4558C159

Hello geovel,

Assuming you have created a dynamic page with the URL:

/profile/{ID}

This means that in order to navigate to a specific profile, you will need to replace {ID} with an actual existing id.

So, for the code above to work, you would need to change it to:

$w("#button6").onClick( (event, $w) => {
    let searchValue = $w("#input12").value;
    wixLocation.to("/profile/" + searchValue);
 } );

When creating the dynamic page, you could replace {ID} with any other field that you have in the relevant collection and want to use for “searching”.

Note, that this assumes that the user inputs a complete & valid existing ID. Meaning, that this is not exactly a search box.
Does this answer your use case ?
Or are you looking for an actual search box that allows a user to input only partial data to search by ?

Hi,
You can see the name of the database and the field in the dynamic’s page name.

Hi Dor, thank you for responding.

Yes, I’m looking for an actual search box that allows a user to input only partial data to search by and the result will go to a dynamic page and display all the information.

Thank you OR. but it’s still not working on me :frowning:

Hello again,

An actual search box can be implemented by querying the database using a filter.
It can be done directly through wixData - https://www.wix.com/code/reference/wix-data.WixDataQuery.html
Or by using a dataset and changing its filter through its api - https://www.wix.com/code/reference/wix-dataset.html#setFilter

Try to look at the above references which should be self explanatory and let us know if you need further help.

Hi Dor,

Greetings from the other side.
Thank you for responding, much appreciated. :slight_smile:


 $w.onReady( () => { 
$w("#myDataset").onReady( () => { 
let itemObj = $w("#myDataset").getCurrentItem(); } ); 
} ); 

I think the code above is what I’m looking for, could you please help me to write some code, I’m not really good at it. Thank you Dor.

Similar question, but connecting your search to open a dynamic page? I have a dynamic page set up to fill with info on cities…want a search box to direct them to whichever city they type in

Hi Jeff,
When you create a dynamic page, a new field is added to your collection which holds the relevant link to the page for each record in the collection.
So assuming you’ve implemented the search logic, and found a specific record, you should just take the link to the dynamic field from the related record’s field and use it to navigate to the page.

Hi, I just want to create a box (where any user can input the ‘registration no.’ and check the result which display whether the ‘registration no.’ is valid or not valid.
When user press check button, it will display the registration no. & the details which i have done in database.
That simple. But i have tried thousand times but failed. Please help me.
My site: club40my.wixsite.com/home
My database:

Please help me

Hi guys,
I have been trying to put togther a serch function ( connecting to a specific database entry and displaying on a dynamic item page) for a few days now … and FINALLY after reading through these threads I have it!

Well to be honest there is a little bug regarding it only working when I double click it. But that aside from that I’m over the moon.

So just thought I would drop a quick note to say “Thanks so much!!” to all above :slight_smile: