I have a displayMath.ejs file. In the file I want to click a button called “Add”. The button will show a popup window, which I have done using javascript. The window will display the calculateAddition.ejs file.
displayMath.ejs
<p>Count: <%= aNumber %></p>
<form class="" action="/displayMath" method="post">
<a class="btn btn-sm" href="/calculateAddition" role="button" onclick="centeredPopup(this.href,'myWindow','500','300','yes');return false">Add</a>
</form>
</div>
The calculateAddition.ejs file will display theANumber and theNewNumber (which is aNumber + 1).
calculateAddition.ejs
<p>Current Count: <%= theANumber %> Next Count: <%= theNewNumber %></p>
App.js
var myNumber = 0;
var myOldNumber = 0;
var myNewNumber = 0;
app.get("/calculateAddition",function(req,res){
res.render("calculateAddition", {
theANumber: myOldNumber,
theNewNumber: myNewNumber
});
});
app.post("/calculateAddition",function(req,res){
myOldNumber = myNumber;
myNewNumber = myNumber+1;
res.render("calculateAddition", {
theANumber: myOldNumber,
theNewNumber: myNewNumber
});
});
But when I do this, the popup always shows Current Count: 0 Next Count: 0. Any help would be appreciated!