Search code examples
javascriptrating

Javascript rating system


I am not a javascript guru so please be patient with me.

I was looking for a good rating with js and I ran to the his blog:

http://www.marcofolio.net/webdesign/jquery_quickie_colourful_rating_system_with_css3.html

The author has a demo and has provided the code to download.

it looks really nice except the fact that it doesn't have the example for saving the colors. Therefore the colors are back to black (default color) once user moves the mouse away.

any idea how to have the colors fixed?


Solution

  • In addition to the code TimDog has added:

    adding

    _rated = false;
    

    to

    $(".fav_rating li label").hover(function() {
    

    resets the colors every time user hovers over the ratings. Then when they click _rated is set to true and therefore prevents the color change

    in addition, i used a hidden input in my form that will contain the value of the rating. To do this my .click looks like following:

    $(".fav_rating li label").click(function(e) {
        e.preventDefault();
        _rated = true;
        $("#item_fav_rating").val($(this).parent().index() + 1)
    });