I'm making a website that displays restaurant in a specific area. The website has a search function where the user can search for a restaurant name and the website will display it. E.G, user input is "A", the search function will bring out restaurant name which start with a, if there is any. I used an express route to return a response of my results as a json file.
app.get("/result/:name", async (req,res) => {
try{
const value = req.params.name;
const result = await getSearch(value);
res.json(result);
} catch (err) {
console.error(err);
res.status(500).send("Database error");
}
})
This is the html for the search bar and the sumbit button.
The frontend:
My goal was to create an event listener that will display the search results, when my search button was clicked. But I was unable to get the search bar text by using ".value". And running this line of code
getInput.addEventListener("click", just_get);
gave me this error:
Uncaught TypeError: getInput.addEventListener is not a function
function getInput(){
const inp = document.getElementById("take");
return inp;
}
getInput.addEventListener("click", just_get);
async function just_get(){
const seacrhing = document.getElementById("search");
const value_sea = seacrhing.value;
const res = await fetch(`http://localhost:8000/result/${value_sea}`);
const data = await res.json();
}
Any suggestions on how I can fix the issue?