sad-ducky
sad-ducky

Reputation: 73

jquery star rating callback

I've been trying to use this jquery star rating plugin: http://www.fyneworks.com/jquery/star-rating/#tab-Overview. I'm trying to get the value of the star once it's clicked but I've been having no luck. I wasn't sure where to include the following callback they suggest:

$('.auto-submit-star').rating({
    callback: function(value, link){
        alert(value);
    }
});

I've tried sticking it around in the code but I get no alert when I click a star. Thanks!!

Upvotes: 4

Views: 3232

Answers (6)

tomwang1013
tomwang1013

Reputation: 1425

https://code.google.com/p/jquery-star-rating-plugin/issues/detail?id=21 refer to this: You must use a selector other than ".star"

Upvotes: 1

Muhammad Haseeb Khan
Muhammad Haseeb Khan

Reputation: 895

Although it's very Old POST but my experience may help someone. I too had the same issue. but able to solve it after generating the code through Ajax, and then at Success callback i invoked the rating plugin. It worked for me. I think it does not detect the class which is created on the DOM.

Upvotes: 0

user851126
user851126

Reputation: 61

$(function(){
    $('input[type=radio].star').rating();
});

Remove the above lines from the jquery.rating.js, and you are all set. I suppose I don't need to explain why as it's intuitive =)

Upvotes: 5

user947830
user947830

Reputation: 31

You need to change the class on the radio buttons from star to auto-submit-star, don't just add auto-submit-star to the existing class of star on the radio buttons. For example mine looks like this:

<input name="star1" type="radio" class="auto-submit-star" value="1"/>

Upvotes: 3

Joseph Silber
Joseph Silber

Reputation: 220136

Did you give your radio buttons the class name of auto-submit-star?

<input type="radio" name="whatever" class="auto-submit-star" />

$('.auto-submit-star') selects all radio buttons with a class of auto-submit-star, and then sets up the rating plugin.


On the other hand, it seems that you might be doing it before DOM ready. In case you don't know what that is:

jQuery(document).ready(function() {
    $('.auto-submit-star').rating({
        callback: function(value, link){
            alert(value);
        }
    });
});

Upvotes: 1

configurator
configurator

Reputation: 41670

Open your browser's developer tools and look in the console log; are there any warnings or error messages? If so, something's wrong in your code. Otherwise, Jospeh's answer is likely correct and your selector ($('.auto-submit-star')) isn't selecting anything.

Upvotes: 0

Related Questions