Hey Guys!
I want to display 3 counters on my page, it should count from zero to something to show how many customers we have etc.
I copied this code from a forum discussion:
let startNum = 6500;
let endNum = 7000;
const duration = 9; // 1000 milliseconds
$w.onReady(function () {
setInterval(()=> {
countUp();
}, duration);
});
function countUp(){
if (startNum <= endNum ){
$w('#text68').text = startNum.toString();
startNum++;
}
}
let startNum1 = 7999980000;
let endNum1 = 8000000000;
const duration1 = 1; // 1000 milliseconds
$w.onReady(function () {
setInterval(()=> {
countUp();
}, duration);
});
function countUp1(){
if (startNum <= endNum ){
$w('#text69').text = startNum.toString();
startNum++;
}
}
The first counter works fine, but i'm struggling with the 2nd and the 3rd. Someone with more coding experience, please provide me a working code, so i just have to make the textboxes and modify the numbers.
Thank you in advance!
import wixData from 'wix-data';
$w.onReady(function () {
wixData.query("DADOS") // DADOS is my database
// you need to remove this .eq("teusmov") from here
.find() //this will return all records in the dataset
.then((results)=> {
let items = results.items; //this will store the rows in an items variable
let item=items[0]; //this will store the first row in an item variable
let teusmov = item.teusmov; //this will store the teusmov value you want in a teusmov variable
$w("#text38").text = teusmov.toString(); //then use the teusmov variable to send to the textbox
});
});
Hope this helps.
what if endNum is a number that is collected from a database?
If you're incrementing all your counters at the same rate, and the first function works, then just build the other 2 around that.
let startNum = 6500; let endNum = 7000; let startNum1 = 7999980000; let endNum1 = 8000000000; const duration = 9; // 1000 milliseconds $w.onReady(function () { setInterval(()=> { countUp(); }, duration); }); function countUp(){ if (startNum <= endNum ){ $w('#text68').text = startNum.toString(); startNum++; } if (startNum1 <= endNum1 ){ $w('#text69').text = startNum1.toString(); startNum1++; } }
and if you're wondering why the second one you posted doesn't work, it is because you are not calling it anywhere that I can see