2

Created a database of products and I want to be able to search for a product, then filter by category. I would also like to be able to filter from all of the products if there is no search. Right now, the search and filter are working independently but if I try to filter after searching, it replaces the search query and just applies the filter.

For example, I could search "abc" and the URL would be http://localhost:1337/search/?search_string=abc. If I filter by "category" after the search, the url would be http://localhost:1337/category. I would like to get a url of http://localhost:1337/search/?search_string=abc/category if this is possible.

Right now I have one ejs file, since the format of the site is pretty much the same for all pages. The only difference is that my app.get methods in my js file filter the products by the search or category, then render only the valid ones to the ejs file. My homepage simply displays all of the products.

Please let me know how I could fix this problem and append to the end of my search query.

edit:

Right now my ejs categories are hyperlinks that append to the end of the url.

<a href="/category">Category</a>

This works for the home page, but the search query part gets eliminated and the url turns into http://localhost:1337/category even if the current URL contains a search query.

  • [get the parameters](https://stackoverflow.com/questions/20089582/how-to-get-a-url-parameter-in-express), and [pass them with the new url](https://stackoverflow.com/questions/49888852/passing-url-parameters-to-other-page-using-express-and-node-js) ? – Luuk Jul 23 '22 at 17:08
  • @Luuk Is it possible to access the parameters in EJS or would I need to render them in the js file first? Also would it be something like Category? Sorry I am pretty new to node and express. – master_coder999 Jul 23 '22 at 17:14
  • I just now (a bit of) JavaScript, and I know how to search for answers, and the tag [tag:ejs] on stackoverflow says: "EJS is a simple templating language that lets you generate HTML markup with plain JavaScript. No religiousness about how to organize things. No reinvention of iteration and control-flow. It's just plain JavaScript." , so your Q:"Is it possible to access the parameters in EJS or would I need to render them in the js file first" is a bit unclear, when taking into account what I said earlier in this comment. – Luuk Jul 23 '22 at 19:22

0 Answers0