Search from footer

Hi everyone, I managed to get this search function working on a single page, but now what I am looking to do is have a search input located in the footer, so that visiters can type in their postcode and it redirects them to my agents page, showing them the closest (or nearby) agents to them.

My problem is keeping information inserted from one page to another basically. I thought about in the following code:

import wixLocation from ‘wix-location’;

export function footerpostsearch_click(event) {
const footeruserpost = parseInt($w(“#footerpostin”).value, 10);
wixLocation.to(“/search?postcode=” + footeruserpost );
}

Once the search page is loaded, it should then grab the users value from the URL and use it on page load. e.g (As a basically example of grabbing the query)

$w.onReady(function () {
$w(“#test_input”).value = wixLocation.query;
});

My problem is, the url is showing up correctly (I’m viewing it on the free published site), but it isn’t grabbing the query for some reason. What am I missing? It grabs the baseUrl fine for example from the wix-location module, but it doesn’t want to play nicely when it comes to the query.

Hey there,

The wixLocation.query property returns an object so you can’t directly assign it to the value of an input element. You’ll need to pull the value from the object.

In your case that should be:

$w.onReady(function () {
  $w("#test_input").value = wixLocation.query.postCode;
});

Thanks, that worked :slight_smile: