Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda