Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!