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

294
Views
Django: How to save javascript auto-increment to django database?

I am incrementing a value from my database evey 3.5 sec using javascript, but the value that i am incremeting is coming dynamically from the database, now i want to save the newly incremented value to the database as the increment keeps going, i don't know how to achieve this using django and javascript.

When i refresh the page, the value resets to the default value that i have in my database and doesn't update the value with the new increments

<span id="generated">{{total_points}}</span>

<!-- This is the js doing the increment function -->
<script>
    var i = {{total_points}};
    function increment() {
    i++;
    document.getElementById('generated').innerHTML = `₦` + Number(i).toLocaleString('en') + `.00`;
    }
    setInterval('increment()', 3140);
</script>

how do i save the new increments to the database? Do i need to provide my models.py?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

The total points and the increment you can save in the javascript value until there is a submit of the form. Then send the result in the request to safe it to the database. If you refresh the page you indeed loose the increment. It might also be interesting for you to safe stuff in localstorage because if the user then refreshes the localstorage is still there, but then you must take localstorage if there is one, {% else ... you must take {{total_points}} to start with, but also with this: Updating stuff to the database requires you to build a form and do a request.

about 4 years ago · Santiago Gelvez 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!