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.
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