Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 614473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:06:56+00:00 2026-05-13T18:06:56+00:00

I’m having trouble converting this 5 star rating script that works perfect with jquery

  • 0

I’m having trouble converting this 5 star rating script that works perfect with jquery revision put out on Date: 2006-09-07 10:12:12 +0200 (Do, 07 Sep 2006) $* $Rev: 276 $

It’s the addclass, removeclass, .extend functions that I think are the problem but I can’t seem to successfully convert it to work with jquery v1.3.2?

Really need this to work asap.

Thanks for all your help… stackoverflow.com ROCKS!

Heres how you call it:

<script type="text/javascript">
$(document).ready(function() {
$('#rate1').rating('postid', { maxvalue:5 });
});
</script>
<div id="rate1" class="rating">&nbsp;</div>

Heres the css:

.rating {
    cursor: pointer;
    margin: 0em;
    display: block;
    float:left;
}
.rating:after {
    content: '.';
    display: block;
    height: 0;
    width: 0;
    clear: both;
    visibility: hidden;
}
.cancel,
.star {
    float: left;
    width: 25px;
    height: 25px;
    overflow: hidden;
    text-indent: -999em;
    cursor: pointer;
}
.cancel,
.cancel a {background: url(delete.gif) no-repeat 0 -25px;}

.star,
.star a {background: url(star.gif) no-repeat 0 0px;}

.cancel a,
.star a {
    display: block;
    width: 100%;
    height: 100%;
    background-position: 0 0px;
}

div.rating div.on a {
    background-position: 0 -25px;
}
div.rating div.hover a,
div.rating div a:hover {
    background-position: 0 -50px;
}

And heres the rating script:

function postrating(i) {
    $("#rate_result").html(i);
}

function doSubmit() {
         var rating = $('#result').html();
         var reviewid = $('#reviewid').html();
         if(rating == '1') {
            alert('Are you kidding me!');
         }
         if(rating == '5') {
            alert('Thanks for the 5 star rating!');
         }
         alert(rating);
         alert(reviewid);
}

$.fn.rating = function(id, options) {
    if(id == null) return;
    var settings = {
        id       : id, // post changes to 
        maxvalue  : 5,   // max number of stars
        curvalue  : 0    // number of selected stars
    };
    if(options) {
       $.extend(settings, options);
    };
    $.extend(settings, {cancel: (settings.maxvalue > 1) ? true : false});
    var container = jQuery(this);
    $.extend(container, {
            averageRating: settings.curvalue,
            id: settings.id
        });
    for(var i= 0; i <= settings.maxvalue ; i++){
        var size = i
        if (i == 0) {
            if(settings.cancel == true){
                 var div = '';
                 container.append(div);
            }
        } 
        else {
             var div = '<div class="star"><a href="javscript:void(0)" onclick="javscript:postrating('+ i +');" title="'+i+' out of 5">'+i+'</a></div>';
             container.append(div);
        }
    }
    var stars = $(container).children('.star');
    stars
            .mouseover(function(){
                event.drain();
                event.fill(this);
            })
            .mouseout(function(){
                event.drain();
                event.reset();
            })
            .focus(function(){
                event.drain();
                event.fill(this)
            })
            .blur(function(){
                event.drain();
                event.reset();
            });
            stars.click(function(){
            if(settings.cancel == true) {
            settings.curvalue = stars.index(this) + 1;
            $.post(container.id, {
                "rating": $(this).children('a')[0].href.split('#')[1] 
            });
            return false;
            }
            else if(settings.maxvalue == 1) {
            settings.curvalue = (settings.curvalue == 0) ? 1 : 0;
            $(this).toggleClass('on');
            $.post(container.id, {
                "rating": $(this).children('a')[0].href.split('#')[1]
            });
            return false;
        }
        return true;
    });
    var event = {
        fill: function(el){ // fill to the current mouse position.
            var index = stars.index(el) + 1;
            stars
                .children('a').css('width', '100%').end()
                .lt(index).addClass('hover').end();
        },
        drain: function() { // drain all the stars.
            stars
                .filter('.on').removeClass('on').end()
                .filter('.hover').removeClass('hover').end();
        },
        reset: function(){ // Reset the stars to the default index.
            stars.lt(settings.curvalue).addClass('on').end();
        }
    }        
    event.reset();
    return(this);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:06:57+00:00Added an answer on May 13, 2026 at 6:06 pm

    .lt() is not a proper function. You are looking for the :lt() selector. Use a .filter in order to use the :lt() selector. Check your code where you have written .lt(foo) and instead write something like:

    .filter(":lt(" + foo + ")")
    

    Alternatively, you may want to look at .prevAll()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Bind the keydown event as well as the change... $("#ddlDeliveryMethod").keydown(function()… May 14, 2026 at 2:05 pm
  • Editorial Team
    Editorial Team added an answer You can use variables from the enclosing scope, a technique… May 14, 2026 at 2:05 pm
  • Editorial Team
    Editorial Team added an answer ^\[(-?\d+\.?\d+?)?/(-?\d+\.?\d+?)?\]:(-?\d+\.?\d+?)/(\d+)$ captures each number in its own group. This assumes… May 14, 2026 at 2:05 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.