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

264
Views
Why isn't the value in my variable (totalSubs) permanently changed with the new assignment after the runSubs funtion?

When the page is reloaded, totalSubs returns back to its original value of 10. Why is this?

var totalSubs = 10;
window.onload = function getSubs() {
document.getElementById('subsNo').textContent= totalSubs;

}

function runSubs() {
var subsNo = Number(document.getElementById('subsNo').textContent);
var NewSubsNo = 0;
NewSubsNo = subsNo + 1;
document.getElementById('subsNo').textContent= NewSubsNo;
return NewSubsNo; 
}

totalSubs = runSubs(totalSubs);

<input type="submit" value="Subscribe" style="width:200px; height:60px; font-size: 2.0rem;" onclick="runSubs()"  onload="getSubs()" />

<p id="subsNo"> </p>

Backend:

var http = require('http');
var fs = require('fs'); 
http.createServer(function (req, res) {   
  fs.readFile('MobileUI.html', function(err, data) {     
    res.writeHead(200, {'Content-Type': 'text/html'});
  res.write(data);
  return res.end();
  });
}).listen(8080);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Store it in the localStorage of a web browser. Currently, you are storing in temporary memory so instead, use local storage.

localStorage.setItem('totalSub', 10);
const getSub = local.getItem('totalSub')
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!