I have an issue where I’m trying to create a count-up counter for my website. How this works is that when users send in a form with a value , the value will be added into the main count-up counter in the homepage.
An example will be: User fills in form and inputs a value of 5
Current Homepage Counter will become 0 + 5
Next User fillls in form and inputs value of 3
Current Homepage Counter will become 5 + 3
due to my lack of knowledge in corvid , hopefully someone can advise me on this. Thanks !
Hello Brandon Sama,
do you look for something like this?
https://mt2-king.wixsite.com/website/test2
Hi Dima,
what I’m looking for is somewhat like this ! May I know how is this done ? Thanks !
But I wish to make it such that the value remains even if I refresh
Hello Brandon,
yes of course you can.
Here is all the CODE which is needed for this what you can see on the example-page…
import wixData from 'wix-data';
$w.onReady(function () {
});
export function button1_click(event) {
$w("#dataset1").onReady( () => {
let NewDataset = {
"title": $w('#input1').value,
"name": $w('#input2').value,
"lastname": $w('#input3').value,
"counter": $w('#input4').value
};
wixData.insert("test2", NewDataset).then( (results) => {
let item = results;
});
});
let myNumber = Number($w("#text1").text);
let myNewInputNumber = Number($w('#input4').value);
$w("#text1").text = ""
$w("#text1").text = (myNumber + myNewInputNumber).toString();
let OPTIONS = $w('#dropdown1').options
OPTIONS.push ({"label": $w('#input1').value + " / " + $w('#input2').value + " / " + $w('#input3').value + " / " + $w('#input4').value , "value": "xxx"})
$w('#dropdown1').options=OPTIONS
}
export function button2_click(event) {
let OPTIONS = $w('#dropdown1').options
OPTIONS.push ({label: "New-Label", value: "NewItem"})
$w('#dropdown1').options=OPTIONS
}
All you need are following elements…
- a DATA-COLLECTION called [“test2”]
- 1x DROPDOWN-MENU
- 4x INPUT-FIELDS
- 1x NORMAL-TEXTFIELD
[“But I wish to make it such that the value remains even if I refresh”]
Yes that is true. All the Data is lost when you do a refresh.
To solve this problem you have to expand your code.
Following steps are needed for this…
- When the page loads —> go to the data-collection and read-out all the inputs at the column (counter). This is the column where all the numbers are saved in. [that can be done for example with a loop]
for (var i = 0; i < [here the length of your Data]; i++) {
...here your code
callculation of all COUNTER-entries in data-collection
}
- then you can take the result and put it where ever you want to have.
For example to the “Counter-Text” which you can see in my example-page.
$w("#text1").text = [YOUR RESULT HERE]