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.


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


The calculateAddition.ejs file will display theANumber and theNewNumber (which is aNumber + 1).


<p>Current Count: <%= theANumber %> Next Count: <%= theNewNumber %></p>


var myNumber = 0;
var myOldNumber = 0;
var myNewNumber = 0;

  res.render("calculateAddition", {
    theANumber: myOldNumber,
    theNewNumber: myNewNumber
  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?

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