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`); }
Great! thanks for the help
the 2nd part is on the results page?
how would I do that? The search is pretty fast, so it probably doesn't matter, but always looking to improve
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).
//imports.... function search(){ let word = $w("#searchbox").value; local.setItem("searchWord", word); wixLocation.to(`/results-1`); } $w.onReady(function () { $w('#serchButton').onClick(search); }); export function searchbox_keyPress(event) { if(event.key === "Enter"){ search(); } }