Passing a Function with parameters in HTML

Asked

Viewed 31 times

0

Aoba, what is it? I’m trying to make a delete in my backend be called in HTML when a person clicks on a certain button. Then I’m passing a src script, to the file that has this Function. And in onclick I’m calling this Function, like this:

const db = require('../backend/db')
const routes = require('./routes')

const ideas = db.run('SELECT * FROM ideas')

function deleteIdeia(id) {
    routes.delete(`/ideias/${id}`)
}

module.exports = deleteIdeia

and the onclick:

<button onclick="deleteIdeia(ideas.id)" />

And delete it on my back:

delete(req, res) {
        const { id } = req.params

        db.run(`DELETE FROM ideas WHERE id = ?`, [id], function (err) {
            if (err) return console.log(err)

            console.log('DELETEI')
        })

        return res.redirect('/ideias')
   }

The problem is that he says that the deleteIdeia function has not been defined. If anyone can help me I thank you!

PS: The function of the backend is working well, I tested it in INSOMNIA.

  • How you are generating this html?

  • With html even. A file . html

  • Then you imported a js in the default Node in html?

  • That, exactly.

  • Checks if your console generates an error when you load the page.

  • No error appears in any

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.