3

I'm using jQuery Raty plugin to enable star rating system on my website.

I've a set of 4 ratable questions(can be 5 too) which I display dynamically using a loop. Hence to display the stars I'm using div id as follows:

    <c:forEach items="${myQuestionList}" var="singleQuestion" varStatus="status">

        <p>${singleQuestion.text}</p>

        <div id="star${status.index+1}"></div>

    </c:forEach>

And the Raty initialization code is as follows:

$("div[id^=star]").raty({ 
                         width: 300
                      });

This works perfectly fine. All my 4(or 5) questions gets displayed and Raty stars get displayed.

Now the problem is this rating is inside a form & needs to be submitted. But the problem is Raty appends a <input type="hidden" name="score"> to each Raty & hence when the form is submitted, it's impossible to say which rating is for which question.

Is there a way I can assign each Raty hidden input element a different name which will help me relate it with the question asked.

Raty documentation says that I can change the score name to anything:

$('#star').raty({ scoreName: 'myscore' });

But that won't help me coz I'm initializing the raty plugin once for all the elements.

How can I solve this problem? Please guide. I'm stuck. :(

LittleLebowski
  • 7,691
  • 13
  • 47
  • 72

1 Answers1

5

OK, I solved it myself.

Here's the solution for anyone stuck at the same point:

scoreName: function(){
                    return $(this).attr('id');
                }

This will set the score name to the id name. You can set it to anything else too.

LittleLebowski
  • 7,691
  • 13
  • 47
  • 72