Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
Post then change text in html nodejs

I have a form tag in Html like then:

app.get("/",(req,res)=>{
res.sendFile(__dirname+"/index.html")

})

app.post("/Cong",urlencodedParser,(req,res)=>{
    var a = parseInt(req.body.a);
    var b = parseInt(req.body.b);
    var c = a + b;
    res.send("Result: "+c)//This is will route to a new website, but I just want change text in my HTML
})
 <form action="/Cong" method="post">
  A: <input type="text" name="a"><br>
  B: <input type="text" name="b"><br>
<label id="result"></label>
</form>

how I can change the label in HTML with id result = value C in file js when I click the button.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Looking at your code, I'm a bit confused about the context you're trying to achieve this in.

In the browser, you would do document.getElementById("result").innerHTML = c

But you don't display the front end code, only the backend, you'd need to call your backend end point from the front end

eg: post to /Cong here's an example in Axios

axios.post('/Cong', {
    a: 1,
    b: 2
  })
  .then(function (response) {
       document.getElementById("result").innerHTML = response;
  })
  .catch(function (error) {
    console.log(error);
  });

Your backend res.send("Result: "+c) should also read res.send(c) as otherwise the front end will get "Result: 3" instead of just 3

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda