How to make a script in the Pug engine

Asked

Viewed 291 times

-1

I’m trying to make a script that contains a function in the Pug engine, but I can’t get it called when the user sends the form, can anyone help me? Follows the code:

html
  head
    title= message
    script.
      funtion validator(){  
        alert("teste");
      }
  body
    h1= message
    form(method ="post", action="/cadastrar/marca")
      input(type="text", name="descricao", id="descricao")
      input(type="submit", onclick="return validator()")
  • What is the HTML generated from this file?

  • <html><head><title>Register Tag</title></head><body><H1>Register Tag</H1><form method="post" action="/register/tag"><input type="text" name="Description"/>input type="Submit" value="save"/></form></body><</html>

  • First, correct the term funtion that should be function.

  • I tested your code with https://html2jade.org/ and could not reproduce the problem. I ask you to edit the question and add more details of how you are generating HTML - and make sure you are generating from the correct file.

1 answer

0

I found the solution, the problem was really the word "Function" that was wrong, thank you very much for the attention, follow the correct code:

html
  head
    title= message
    script(src="validator.min.js")
    script.
      function teste(){
        alert("Teste")
      }
  body
    h1= message
    form(method ="post", action="/cadastrar/marca", onclick="return teste();")
      input(type="text", name="descricao")
      input(type="submit", value="save")
  • And why in your comment about the generated HTML there was no script tag?

Browser other questions tagged

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