J
J
Jake Taylor2022-01-25 12:16:47
JavaScript
Jake Taylor, 2022-01-25 12:16:47

How to handle onkeyup event and process in Node JS?

I am writing the server part in Node.JS, using a plugin expressand a view engine handlebars.

There is a request processing at the root address:

exports.index = function (request, response) {
    let searchValue = request.body.input;

    response.render('index.hbs', {
        title: 'Gifts main page',
        text: 'This is the left box',
        gifts: searchGiftCertificates(searchValue)
    });
}


index.hbsUsing an expression {{{body}}}, a template is included in the file header.hbs, which:
1. contains a field input(search string) with an event onkeyup:
<input id="search" onkeyup="searchGiftCertificates()" placeholder="Search by item name">


2. Contains the expression {{gifts}}, which is a parsed JSON file and is output using the expression {{#each gifts}}

During the execution, I had a question, how to properly handle the event onkeyupon the Node.JS side or how to do it? You need to take the value of the field inputby event onkeyupand somehow transfer it to Node JS in order to exports.index = function (request, response) {process and pass the data (JSON) to the expression in the function above gifts: searchGiftCertificates(searchValue)to handlebarsdisplay the data on the page, in accordance with the search query.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question