Click counter

I cheked page and i actually can’t find “#noButton” component. When this function (counting clicks should happen?)

I have text boxes that have links to a download - I was using the onClick for the text box. Does it need to be changed to a button?

Sorry but i don’t understand you

When you want to count clicks on some element - you should select this element, andd funxction to onClick event (via properties panel) and add your code to the generated block of code

On your site i don’t see any elemend with id “noButton”, so this function will never execute

Please, read article here

Especially this part - 2. Set Up an Element to React to a User Action

I had changed my code from “noButton” to the name of my text box that people will click: “InstructionalManualtext”. I used the code generated from the properties panel.

This is what i see:
https://www.screencast.com/t/t0mtmPjkcoF

This text has on click event with one name, but handler for this event has another name
Delete this existing handler and create new one, and then paste you code for counting clicks inside this new event handler

I must not have saved the change - but it’s in there now!

However still not working after saving the change.

this function which you renamed doesn’t have any connection with the text click event.
Again, please read article about creating event handlers - i can’t explain you better than it’s explained there.

I believe I may have fixed what you are referring to!

Or are you referring to “export function InstructionalManualtext_click() {” not having “…click(event) {”?

Because that prompts another error, and I read in another forum to delete that, which has worked for my other codes.

Either way the problem remains.

So good time of the day.

I have new ideas how to explain it)

Problem in your case is that there is no connection between event handler in properties panel (https://www.screencast.com/t/fBL9XajTGC)
And function which should be executed when action (click in this case) happen

Best way to fix this is to delete everything in onclick event, create new one and add your code to this new function. I made a video:
https://www.screencast.com/t/3rklPguu

Hi Mikhail! Thanks for that. I did fix that yesterday, that’s unfortunately not the problem though. For good measure I started over and redid the whole thing just now, all of the event handlers are accurate.

The ID problem is still there.

Hey, I’ve already implemented code like this and I know it works because I’ve tested it myself and saw that the counter increments. The problem is that I’m not noticing any change when other users click on it, because I’m getting subscribers through it.
Is there any reason why the code might not work for other users? Is it because they might have javascripts deactivated?

Hi Mikhail! I’m try to count how many click on the data and follow your code as following. Could you tell me what I did wrong?
My database called “NewCollectionName”
the counter field called “NOC” // number of click

import wixData from ‘wix-data’;
export function text2_click(event, $w) {
wixData.query(“NewCollectionName”).eq(‘Title’,$w(’ #text2 ‘).text).find().then((result) => {
let answersitem = result.items[0];
let id = answersitem._id;
answersitem.Noc++;
wixData.update(“NewCollectionName”,answersitem).then(()=>{
$w(’ #dataset2 ').refresh();
});
})
}

Hi!

So what are the syptoms, what actually happens when you try to run this code?
I believe you should check content of answersitem before updating db - this is first thing to check. Dos it really change?

Actually, it shows nothing. But you’re right, the content of answersitem seems nothing inside which means my query maybe wrong. I change my code as following to check the answeritem, and $w(‘#text9’).text doesn’t make any change, as well as no error msg. Comes with me database picture for your reference. Thanks! Anything I get wrongly?

export function text2_click(event, $w) {
let clicktitle = $w(‘#text2’).text;

wixData.query(“NewCollectionName”).eq(‘Title’,clicktitle).find().then((result) => {
let answersitem = result.items[0];
let id = answersitem._id;
answersitem.Noc++;
$w(‘#text9’).text = answersitem.Title;
// wixData.update(“NewCollectionName”,answersitem).then(()=>{
// $w(‘#dataset2’).refresh();
// });
});

You syncronized collections, right? I mean live collection has data?

And second idea -
https://www.screencast.com/t/2WTRQiIqH

I see that in query code you used field name instead of actual field key

‘Title’ is name, but field key is ‘title’ (it’s just guess, i don’t see on screens your real field key)
And such things are commonly case-sensitive, so try to chyange query to this:

wixData.query(“NewCollectionName”).eq(‘title’,clicktitle).find().then((result) => {

Thanks Mikhail! You got the point, case-sensitive is key of the problem. But not only “title”, “Noc” also is a problem. The final code is following:

wixData.query(“NewCollectionName”).eq(‘title’,clicktitle).find().then((result) => {
let answersitem = result.items[0];
let id = answersitem._id;
answersitem.noc++; // instead of "answeritem.Noc //

Thanks again! : >

Hey Mikhail! I have looked through the other posts, and still can’t figure out why it’s not working for me. My collection is called Artists and there is only field, likeField. I’m using #text71 as my output to display the number of likes for the user. Any ideas as to why this isn’t working?

Hi! First of all, i can’t understand what does this mean - …eq(‘title’,$w(‘#likeButton’)).find…

for eq operator you need to pass key field as first paramenter and smth to compare with as 2nd parameter - should be some value
But, youre passing whole component as 2nd parameter - $w(‘#likeButton’)