When I have click on checkbox then req.body.task return undefined
.
<input type="checkbox" name="task" autocomplete="off" checked="" onchange="onToDochange({{id}})">
Perform on change function which return id of checked or unchecked checkbox.
function onToDochange(id) {
// console.log(id);
fetch('/checkbox', {
method: 'POST',
body: JSON.stringify({global: id})
})
.then(res=>res.json())
.then(res => console.log(res));
};
Routing
app.post('/checkbox', (req, res) => {
console.log(req.body.task);
});
Working with expressJS nodeJs template engine handlebars