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!