I currently have a search box that is triggered when you press enter. I would like to have a second option of triggering it when you press the search button, so you can either press enter or press the button. My knowledge of code is pretty limited so I need it to be really simple.
All help appreciated.
This is my current code:
import { local } from ‘wix-storage’ ;
import wixLocation from ‘wix-location’ ;
$w . onReady ( function () {
});
export function searchbox_keyPress ( event , $w ) { if ( event . key === “Enter” ){
console . log ( “Enter was pressed!” )
**let** word = $w ( "#searchbox" ). value ;
local . setItem ( "searchWord" , word );
wixLocation . to ( `/results-1` );
Awesome! That worked! I tried so many different things, but I kept getting something wrong (as it happens when you don’t really understand the code you are writing).
You’re welcome.
You may want to consider storing the search term in the memory (import {memory} from ‘wix-storage’; etc…) or pass it via the URL query parameters (I think it should be a little bit faster than local storage. But maybe it’s negligible).