csspd net
csspd net

Reputation: 11

Pug JS Express running a function from pug

A pug file with button(onclick) run the function in js file, if both of the files are inside the public and views folder or both of the files are out of the views and public folders.

How can I run the function from the pug file; When pug file in Views folder and js file in out of the public and views folders?

Thanks


pug file: In views folder
button.btn.btn-primary(onclick='myfunc()') Function 1

js file: out of views and public folders

function myfunc(){
    console.log('Hi');
  }

I try to run a function from a pug file with button(onclick)

Upvotes: 0

Views: 377

Answers (1)

csspd net
csspd net

Reputation: 11

I think I solved the problem.

In the pug file:

          form(action="/test" method="POST")                                    
                    .form-group
                        input(type="submit" value="submit").btn.btn-danger

In the JS file:

            export function posttest  (req, res, next) {

                const myfunc = () => {
                    console.log("hi");  
                }

                myfunc()
            }

And I added a route for posttest

Upvotes: 1

Related Questions