Setting CStarRating via JavaScript

I am trying to use a CStarRating widget and need help setting the value from a javascript. Here is my widget:





I have a javascript function elsewhere on the page and am trying to do something similar to the following:

<a href="#" onclick="setRating(value);">Set rating to my new value</a>

<script type="text/javascript">

function setRating(v){

  stars = document.getElementById('rating');

  for (i=0;i<stars.length;i++){ 

     if(stars[i].value == v){ 

        stars[i].checked = true;





I need to call the JavaScript because the widget has already been rendered on the page.

So, if I call setRating(3), for example, the widget should select the 3rd star. I am new to Yii and confused how to make this happen. Any help would be greatly appreciated. Thanks!

Can anybody point me in the right direction with this?


find your answer here in the official docs:

just as simple as:


use this script , I had used it after a lot of search


don’t forget to put your rating in a form