0

I am using star rating plugin and in the star selection its return value in number that I am able to use it. Now I want to add another functionality on this that is, when I select star 1, it should show some message and the similar with star2, star 3 and so on.

The value of each star selection would in the array, but I am not able to print successfully, following

How do I show the message on each star selected?

$('rating').starrr({
    change: function(e, value) {
        console.log(value);

        //this is message
        var ratingMsgs = [
            'star 1 selected',
            'star 2 selected',
            'star 3 selected',
            'star 4 selected',
            'star 5 selected'
        ];
        var ratingMsg = $("p.message");
        //This is just showing the first value, but I want to value conditionally 
        ratingMsg.removeClass('hidden').append(ratingMsgs[0]);
    }
});
6
  • What do you get in console.log(value); Commented May 11, 2018 at 9:55
  • Change ratingMsgs[0] to ratingMsgs[value] Commented May 11, 2018 at 9:55
  • why are you doing .append(ratingMsg[0]) ratingMsg[index] this index should point to user selection Commented May 11, 2018 at 9:55
  • number, like if I click 1 star then 1..if clicked 5 and 5 in number Commented May 11, 2018 at 9:56
  • @Dean Yes its binding correctly. Commented May 11, 2018 at 9:56

1 Answer 1

1

Instead of ratingMsgs[0], give ratingMsgs[value - 1] and text instead of append

ratingMsg.removeClass('hidden').text(ratingMsgs[ value - 1 ]);
Sign up to request clarification or add additional context in comments.

3 Comments

thanks for the answer, I have updated based on your suggestion but what I am getting it, if I am click on star, message of star 1 should show, but its starting from star 2.
Try with value - 1
Excellent, worked as expected. thanks alot! +1 for the instant reply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.