NodeJS/Express-How to calculate and display new value on popup?

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!

in the first line of your code where does the <p< tag end?
like

<p>Count: <%= aNumber %> </p>

also maybe use a callstack? so you can see what your code does excatly?

1 Like

Thank you, sorry that was a typo! Oh a callstack? I have never done that before! I will look into it.