Quantcast
Viewing all articles
Browse latest Browse all 1567

How do I make my JavaScript know the index number of the post I want to delete?

This is the second question I'm asking about this capstone project!

For the project, I need to make it possible to delete and edit posts. I'm focusing on the delete part now, but I don't know where to start. I want to make it so I click the button on the post and it deletes the correct post based on the index number, but I don't know how to send the index of the post selected to the JavaScript?

Here's some of the code:

<% if ((locals.ptit)) {%><% for (let index = 1 ; index < ptit.length; index++) { %><div class="post"><h1><%= ptit[index] %></h1><p><%= stuff[index] %></p><form action="/delete" method="DELETE"><input type="submit" value="POST IS DONE" class="donebtn" name=index/></form></div><% } %><% } %>

^ that is the EJS and v is the JS

app.delete("/delete" (req, res) => {titles.push(req.body["puttit"]);posts.push(req.body["posty"]);res.render("blog.ejs", {ptit: titles,stuff: posts,});})

I've tried to search this to the best of my ability but I feel like I'm missing too much...


Viewing all articles
Browse latest Browse all 1567

Trending Articles