Search input on Header not working on every page

Question:
Hi Everyone,

I have created a search input in my header, which then runs and takes the user to a results page. I have added the code below.

It works from the homepage, but when you arrive on the search page the search bar still appears in the header, but no longer works. Does anyone have any ideas please?

Product:
Wix Editor

import {local} from ‘wix-storage’;

import wixLocation from ‘wix-location’;

$w.onReady(function () {

});

$w(“#searchBarHeader”).onKeyPress( (event) => {
if(event.key === “Enter”){

let word = $w("#searchBarHeader").value;

local.setItem("searchWord", word);

wixLocation.to(`/school-search`);}

});

  1. First of all where did you place the code?

If you placed the SEARCHBAR into the HEADER → then i assume you have added your code to the MASTER-PAGE ?

  1. Your → $w.onReady() <— is totaly useless the way you placed it in your code.
import {local} from ‘wix-storage’;
import wixLocation from ‘wix-location’;
//------------------------------------------

$w.onReady(()=> {
   $w('#searchBarHeader').onKeyPress((event)=> {
      if(event.key === 'Enter'){
         let word = $w('#searchBarHeader').value;
         local.setItem('searchWord', word);
         wixLocation.to(`/school-search`);
      }
   });
});

Hi Dima,

Thank you for replying. Yes I placed it in the Master. Let me try this code change - really appreciate it.

1 Like

Hi Dima,

For some reason the site is unhappy with the import commands?

COPY-PASTE FAILURE thanks to the FORUM CODE-EDITOR, which is not capable to do the COPY & PASTE properly. I corrected only the bottom part, forgot about the TOP part of code.

REPLACE THE QUOTATION-MARKS → these are wrong.