I have tried and tried but this simply doesn´t work. The most confusing thing is that you are told to not connect the input element to the database. But when you don´t do that there becomes no change in the display element when a user click on a star. When the input element is connected to the database it at least show a star in the display element but every time the page is loaded there are no earlier ratings left because it seems to be reset to 0 every time. This makes me crazy so please give me a clear description and don´t tell me to look at the Ratings by User template because I have done that but it doesn´t help me either (a complete different setup with a lightbox which I don´t have any use for):
https://support.wix.com/en/article/velo-tutorial-capturing-and-displaying-ratings
When I review the page I get this yellow line about the code so what do you think I have to add or change?
“Wix code SDK Warning: The numRatings parameter that is passed to the numRatings method cannot be set to null or undefined”.
You aren’t getting an error, only a warning. The issue shouldn’t affect the execution.
The Ratings by User uses a Lightbox, but that doesn’t mean that you need to as well. It’s just demonstration of the Rating element.
Thanks Yisrael for the explanation but I still don´t understand the differences between the code on the page I linked to and the “Ratings by User” code? My main problem is that the total ratings are not saved so when I load the page again the last ratings are gone. How can I solve that? The page I linked to does not show a stats collection while “Ratings by User” shows such a collection. Very confusing…
Another thing that troubles me is that when a user click for a rating the total numbers are not increasing with just one but with three, so if the total number is 26 when he click the number suddenly show 29 
@kricke73 The tutorial that you link to does have a collection for the ratings. This is the explanation on how to set it up.
I’m not really that familiar with the tutorial, but I don’t know why it should increase by 3. What is your code for saving the visitor’s rating?
@yisrael-wix This is the code I use and I have created the fields heterosexRating, heterosexNumber and heterosexTotal because I´m making a sex site
I have been able to make the rating display element show the correct rating but when I go back to the page and click for a new rating the total rating is gone. Very frustrating because I have a field for that wich also are connected with the dataset:
export function ratingsInput1_change(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
$w(“#dataset2”).onReady(() => {
// get the current item from the dataset
const currentItem = $w(“#dataset2”).getCurrentItem();
// get the current average rating, number of ratings, and
//total ratings for the current dataset item
const average = currentItem.heterosexRating;
const count = currentItem.heterosexNumber;
const total = currentItem.heterosexTotal;
// get the new rating from the ratings input
const newRating = $w(‘#ratingsInput1’).value;
// calculate the new average rating based on the current
//average and count
const newAverageLong = (total + newRating) / (count +1);
// Round the average rating to 1 decimal point
const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1);
// set the dataset fields to the new average, total
// ratings, and number of ratings
$w(‘#dataset2’).setFieldValues({
‘heterosexRating’: newAverageShort,
‘heterosexTotal’: total + newRating,
‘heterosexNumber’: (count + 1)
});
// save the dataset fields to the collection
$w(‘#dataset2’).save()
.catch((err) => {
console.log(‘could not save new rating’);
});
});
// Add your code for this event here:
}
@kricke73 You should not be using dataset.onReady() here. Dataset.onReady() is to be defined once (and only once) in the page’s onReady() only if you need to use the dataset when the page is ready. After that, the page is ready and you don’t need the dataset.onReady() again. And yes, I realize that the tutorial says to do this, but it’s wrong. I am sending this on to the relevant team for evaluation.
I’m not sure what else is going on in your code. Perhaps you have a bug, or maybe there’s another issue. Please send me the link to the site and explain how I can reproduce this problem.
@yisrael-wix Just that I get a displayed rating but with 0 counted numbers.
@kricke73 The displayed rating (3 stars) is the default when there are no ratings.
@yisrael-wix Okay, shall I not use .onReady at all when it comes to rating coding? Then I really need to have something clarified; do I need to connect RatingsInput1 to the database or not? Finally I wanna know why the code doesn´t collect the total amount of ratings? I don´t think there is a need to link to my site because I have simply used the code I pasted here and added the fields I wrote in my description.
@kricke73 The dataset onReady() event handler is not needed anywhere except in the page’s onReady() if you need to use the dataset as soon as the page is ready.
You should make sure that you have everything set up on your page as described in the tutorial . As stated in the docs:
*Add the following elements:*
-
A Ratings Display element connected to the new Number fields in your collection.
-
A Ratings Input element your visitors can use to pick a rating for the item. You can use the default setting for the ratings, or define your own. Do not connect it to the dataset.
@yisrael-wix Okay, shouldnt it just be empty stars? 
@yisrael-wix I have done that but when I didn´t connect the Ratings input to the database nothing happends when a user click to rate a video. Are you sure of that it is not needed to connect the input to the database?
Can you please tell me if this code looks correct? A strange thing is that for every rate-click it updates the rating display with more than one. If it shows 5 from the start a click makes it show 9. Extremely confusing! 
export function ratingsInput1_change ( event ) {
// get the current item from the dataset
// get the current average rating, number of ratings, and
// total ratings for the current dataset item
const currentItem = $w ( “#dataset2” ). getCurrentItem ();
const average = currentItem . heterosexRating ;
const count = currentItem . heterosexNumber ;
const total = currentItem . heterosexTotal ;
const newRating = $w ( ‘#ratingsInput1’ ). value ;
const newAverageLong = ( total + newRating ) / ( count + 1 );
const newAverageShort = Number . parseFloat ( newAverageLong ). toFixed ( 1 );
$w ( ‘#dataset2’ ). setFieldValues ({
‘heterosexRating’ : newAverageShort ,
‘heterosexTotal’ : total + newRating ,
‘heterosexNumber’ : ( count + 1 )
});
$w ( ‘#dataset2’ ). save ()
console . log ( “Rating completed.” )
}
I don’t see anything right off with the snippet that you posted. However, without context I can’t say what else might be causing the jump in the number.
You can add some console.log() statements to find out what’s happening and when.
@yisrael-wix Please give me your e-post adress and I will give you permission to log in on my page edition and you are also allowed to edit the code if necessary. Alternatively write directly to kricke73@gmail.com