# help with ratings input/display

**URL:** <https://forum.wixstudio.com/t/help-with-ratings-input-display/12570>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [February 3, 2019, 3:36pm UTC](https://forum.wixstudio.com/t/help-with-ratings-input-display/12570 "2019-02-03T15:36:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![whitneybt](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/whitneybt/32/8836_2.png) [@whitneybt](https://forum.wixstudio.com/u/whitneybt)\
**Post date:** [February 3, 2019, 3:36pm UTC](https://forum.wixstudio.com/t/help-with-ratings-input-display/12570/1 "2019-02-03T15:36:07Z")

</div>

Preview reads ‘script error.’ What could I be missing? Script/instructions taken from [Velo Tutorial: Capturing and Displaying Ratings | Help Center | Wix.com](https://support.wix.com/en/article/wix-code-tutorial-capturing-and-displaying-ratings)

export function ratingsInput1\_change(event) { $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.average;  
const count = currentItem.numberSubmitted;  
const total = currentItem.sum;

// 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({  
‘average’: newAverageShort,  
‘sum’: total + newRating,  
‘numberSubmitted’: (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:  
}

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [February 3, 2019, 3:38pm UTC](https://forum.wixstudio.com/t/help-with-ratings-input-display/12570/2 "2019-02-03T15:38:23Z")

</div>

See this complete example:

#### **Ratings Input and Display**

Let users [rate](https://www.wix.com/code/home/forum/wix-tips-and-updates/example-ratingsinput-and-ratingsdisplay) recipes and display the rating results.

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [February 3, 2019, 3:40pm UTC](https://forum.wixstudio.com/t/help-with-ratings-input-display/12570/3 "2019-02-03T15:40:12Z")

</div>

Note that you do not need a dataset onReady() function in the change() event. The dataset’s onReady() function is only needed in the page’s onReady() function.
