Click counter

oooh, so after I made my changes it seems to work.
https://puu.sh/zX1oo/ae59ac736b.png
https://puu.sh/zX1pE/0600819372.png
That is my new code. And it is using [likefield] instead of likefield on the datebase.

The issue I am having now is how to get the number of likes to stay on screen. The number of likes only gets displayed for 1 second after I click the button, then it disappears.

Another question I have is, if I have multiple like buttons to connect them to the correct row on the database, would I just change this line of code:
let answersitem = result.items;
I would just change the x value to the corresponding row, right?

Mikhail, are you still there? So this codes works such that it increases the like counter field. However I am still stuck on how to get the number to stay on screen.
Doing:
$w(‘#text71’).text = answersitem.likefield.toString();

Displays the number of likes for 1 second, then the number disappears. How do I get this number to stay?

Hi, i guess i know what happens here

Field names are case-sensitive. In code you used “linkfield”, but from content manager view it looks like your field is named “linkField”. That means that after code is executed, it addes likes to feild “linkfield”

At the same time, on page, your text field (i believe) is connected to text to show number of likes
In code you first assign text element to number of likes which you get from collection (and you see this number) and then refresh dataset, which results in taking variable from current item from database, with field key “linkItem”

It’s empty and your text becomes empty

Ask more questions if needed

hello mikhail,
how can i make a dataset save the random number obtained from this code to a db
export function button1_click(event) { $w(" #text3 ").text = (Math.floor((Math.random() * 20) + 1)).toString(); }

Hello Mikhail,

I copy pasted ur code into my website on my button as onClick event and it still doesn’t work. Nothing is being added to the collection at all. Any ideas why?

hi, how can i add a button using wix code to increment a text field by 1 and at the same time onclick on this button to be linked to an external url

Hello Can someone help me how to create a download counter using a button and a testo that shows how many times it was downloaded? Thank you

You are better off posting your question in a new post rather than jump onto the end of an old post like this.

If the code from Mikhail isn’t suitable for you then read below…

You can do it simply through Custom Tracking as shown here.
https://www.wix.com/corvid/reference/wix-window.trackingParameters.html#CustomEvent
How to Use Wix Code with Marketing Tools to Create Custom Events (Youtube video)

How can i have the first value to be zero on yesffield?

I don’t understand how to use “id”:

let id = answersitem._id; // this will be used for writing data back.

please advise