Yii Framework Forum: Setting CStarRating via JavaScript - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Setting CStarRating via JavaScript Rate Topic: -----

#1 User is offline   DDI 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 26-April 11

  Posted 13 March 2012 - 01:38 PM

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!
0

#2 User is offline   DDI 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 26-April 11

Posted 15 March 2012 - 03:31 PM

Can anybody point me in the right direction with this?
0

#3 User is offline   pheadeaux 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 18-March 12

Posted 17 August 2012 - 08:56 AM

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) 

0

#4 User is offline   muhammad123 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 16-August 12

Posted 27 April 2013 - 04:53 PM

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users