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:




$this->widget('CStarRating',array(

     'name'=>'rating',                            

     'maxRating'=>5

));



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;

     }

  }

}

</script>



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?

Hi DDI,

find your answer here in the official docs:


www.fyneworks.com/jquery/star-rating/#tab-API

just as simple as:


$('input').rating('select',3) 

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

$("input[type=radio]","#form_id").rating("select",value);

don’t forget to put your rating in a form