I had a user input for user to input keyword for searching. When they click the search button, it works properly when the user clicks the search button by mouse, but there is no response when the user presses the ENTER key.
What’s the code for Enter Key?
Any help would be greatly appreciated!
Thank you so much for helping out. I have been struggling with this for months, as I am not a coder. When I delete the last export function in your code… it WORKS! So amazing… Your are much appreciated. Thank you thank you thank you
I would like to apply your code on 3 different search bars on the same page, how do I write/repeat the code? I have tried with the below code, but it doesn’t work. Hope that you can help again.
import { local } from ‘wix-storage’;
import wixLocation from ‘wix-location’;
function runSearch(){
let word = $w(“#search1”).value;
local.setItem(“searchWord”, word);
wixLocation.to(/hotelresultpage);
}
$w.onReady( function () {
$w(“#search1”).onKeyPress( (event) => {
if(event.key === “Enter”){
runSearch();
}
let word = $w(“#search2”).value;
local.setItem(“searchWord”, word);
wixLocation.to(/restaurantresultpage);
}
$w.onReady( function () {
$w(“#search2”).onKeyPress( (event) => {
if(event.key === “Enter”){
runSearch();
}
let word = $w(“#search3”).value;
local.setItem(“searchWord”, word);
wixLocation.to(/shoppingresultpage);
}
$w.onReady( function () {
$w(“#search3”).onKeyPress( (event) => {
if(event.key === “Enter”){
runSearch();
}
})
});
You are amazing. It works!! You really just saved me and my project.
I have one last questions, I hope that you can help. This is a further search from the result page. How do I add the “enter key press” code in the below code. Hope that you can help me with the last one. Thank you!!