You have several errors:
-
onClick has to be inside $w.onReady block
-
dataset.onReady should not be inside the loop
-
dataset.onReady should not beinside an event handler (it may get ready prior to the click
-
Instead of saving on loop, you’re better change all the items you need and then save them all together with a direct bulkUpdate (then dataset.refresh() to reload the contents).
https://www.wix.com/velo/reference/wix-data/bulkupdate
https://www.wix.com/velo/reference/wix-dataset/dataset/refresh