samedi 22 mai 2021

Checkbox value is refreshed after page reload in node JS

"I am creating TODO list using Node as backend. after adding every new item, a checkbox is also generating in front of them so I can apply "CSS line-through" to let user know that item is done or of no use. But when I add another item, the page refreshes and that checkbox is unchecked as I am not storing that value anywhere. Can you tell me how to store the value of that checkbox in the backend?

HTML -

<div class="box" >  
    <% for (var i=0; i<newListItems.length; i++) { %>
    <div class="item">
        <input type="checkbox" id="checkBox">
        <p> <%= newListItems[i] %> </p>
    </div>
    <% } %>
    <form action="/" method="post" class="item">
        <input class="inputBox" type="text" name="newItem" placeholder="New item" autocomplete="off" required="required"> 
        <button type="submit" name="list" value=<%= listTitle%>> +</button>
    </form>
</div>

Node JS -

const items = [];

app.post("/", function(req, res){

let item = req.body.newItem;
    items.push(item);
    res.redirect("/");

});




Aucun commentaire:

Enregistrer un commentaire