Click counter

Please screenshot the error you are seeing Adam.

@contact53319

@adcatch02

Have a quick check of your permissions for your dataset to see if that is causing the error.

See previous post with reply from Sapir (Wix Mod) for more info.
https://www.wix.com/corvid/forum/community-discussion/getting-script-error-on-database-save

Thanks i have set the page to ‘everyone’ so there should be no problem there.

i’m lost as to why this won’t work at the moment.

maybe this code is on the wrong page

  1. $w.onReady(() => {

  2. $w(’ #click0 ').value = 0;

  3. $w(’ #dataset6 ').onReady(() => {

  4. $w(’ #dataset6 ‘).setFieldValue(“totalClicks”, $w(’ #click0 ').value);

  5. });

  6. });
    I have a homage where the actual click counter is displayed
    A page that creates new profiles
    and of course the dynamic page that has the onClick event to add a number to total clicks in the collection

Progress to report i put click0 code on the same page as the total clicks code and script error removed and link to next page now works. This is great.

I’m not seeing a number appear under the total clicks field key though so no updating of click counter.

i have linked a text box to total clicks field key on my profile page which i thought would show an increase by populating the field key with 0 to begin with when using total click and click0 code together

guys i’ve totally got it thanks so, so much for everyone’s input (all Ninja’s and particularly Heath. Thanks again. the user input just needed to be populated with initial text of 0 also. I love you guys.

Now, to try and add suppressAuth, to enable not logged in users to be able to add an incremental number to this click counter.

Hi all!

I’m no coder and have been struggling to figure out what the issue is with my click counter function.

Aim:

To count the number of button clicks on a static page and for this number to display in a dataset collection. There will be several buttons on the page so ideally each button would correspond with a different row in the dataset and number of clicks registered under the column of the ‘totalClicks’ field key.

Problem:

I have labeled and connected the elements as best I can, though ultimately I think it’s likely where the discrepancy is.

I don’t see where the code represented below knows which row to enter the data. It appears I am only defining the column field key ‘totalClicks’, but not the row.

Definitions:

buttonDrizzle = button to trigger register of +1 click on the counter

RecipeVotes = dataset collection

totalClicks = Field key of column where number of clicks are recorded

datasetVote = dataset widget on static page

Page Code:

Pulled from:
https://www.wix.com/corvid/forum/main/comment/5a0b6fc607f0c4001427a704

import wixData from ‘wix-data’ ;

export function buttonDrizzle_click(event) {

wixData.query( "RecipeVotes" ).find().then((result)=>{ 

let answersitem = result.items[ 0 ]; //item with values
let id = answersitem._id; // this will be used for
//writing data back

    answersitem.totalclicks++;  // increment field with yes by 1 

// write updated value back to collection
wixData.update( “RecipeVotes” , answersitem).then(()=>{
// refresh dataset to show new value
//(this should be done in promise,
//after updating collection)
$w( “#datasetVote” ).refresh();
});
}) ;

$w( “#buttonDrizzle” ).hide();
$w( “#thanksDrizzle” ).show();

}

Screenshots:

Would really appreciate any help or insight with this :slight_smile:

Leo