I have the following ejs file and I want to capture the NAME field value inorder to fetch the respective details from database and display onto another page. I know how to do this using form tag, but I am unsure how to capture in this case. Any help would be appreciated. Thanks.
search.ejs file:
<a href="/menu/<%= tablelist[i].NAME %>">
<img alt="<%= tablelist[i].NAME %>" class="restaurant-card-cover" src="<%= tablelist[i].IMAGELINK %>" style="height: 115px;">
<div class="restaurant-card-content-text">
<div id="catererName" class="restaurant-card-name heading-color" variable="<%= tablelist[i].NAME %>"><%= tablelist[i].NAME %></div>
<div class="card-description"><%= tablelist[i].DESC2 %></div></a>
In app.js file, I added the following:
app.get('/menu/:name', routes.menu(ibmdb,connString));
And, I have another folder "routes" and I am mentioning all my SQL queries in index.js file. Here it is:
exports.menu = function(ibmdb,connString) {
return function(req, res) {
var name = req.param.name;
ibmdb.open(connString, function(err, conn) {
if (err ) {
res.send("error occurred " + err.message);
}
else {
conn.query("SELECT ITEM_NAME, PRICE FROM HOMEBASEDAPP.MENU WHERE CATERER_NAME='"+name+"';", function(err, tables, moreResultSets) {
if ( !err ) {
res.render('menu', {"tablelist" : tables, name: name});
} else {
res.send("error occurred " + err.message);
}
/*
Close the connection to the database
param 1: The callback function to execute on completion of close function.
*/
conn.close(function(){
console.log("Connection Closed");
});
});
}
} );
}
}
I tried to print the "name" in menu.ejs file but its not getting the value.