How to insert user input into a database after hitting "enter"key

Hello, I have a simple search bar and button. When the user enters a value into the search bar (ID name #input1) I managed to figure out how to send that user input to a dynamic page (named results) after clicking the submit button (ID name #button1) or after hitting the enter key. Here is the code that works:

import wixLocation from 'wix-location';
function goSearch(){
 let word = $w("#input1").value;
 wixLocation.to(`/results/`+ word);
}
$w.onReady(function () {
 $w("#input1").onKeyPress( (event) => {
 if(event.key === "Enter"){
  goSearch();
  }
 })
}); 
export function button1_click(event) { 
 goSearch();
}

Basically, the user enters in a value and either hits return or the enter key and the value is used to generate a dynamic page named after that user value. The dynamic page then pulls in some data from a database.

Now my issue: How can I also have that user input value put into a new database as part of this sequence of events. I figured out how to connect the user input to a new database after the user clicks the submit button. That was pretty straight forward using the Wix developer platform. But I can’t figure out how to get that input data after the user hits the ‘Enter’ key. Basically, I’m just trying to capture the user input data into a new database after the user submits it - either after clicking the submit button or hitting the enter or return key. Thank you!

Thank you so much. Working great.

1 Like