I'm using jQuery Stars Rating plugin ( http://www.fyneworks.com/jquery/star-rating/ ).
I'm having difficulty displaying an existing rating using the plugin's API. Everything works unless there is an existing rating in the database. If there is one, the following block of code will execute, and a 10 new ratings (that's as many inputs I have in my form) get sent to the back-end rating function.
<cfif aRating.recordCount>
<script type="text/javascript">
$(document).ready(function() {
$('input').rating('select','#aRating.rating#');
});
</script>
</cfif>
This ajax call should ONLY execute when a user clicks on the stars
// Ajax submit rating
$('.star').rating({
callback: function(value, link){
$.ajax({
type: "POST",
url: "#URLFor(controller="membros", action="rateGame", key=gameProfile.id)#",
data: "rating="+value,
dataType: "json",
success: function(response) {
}
});
}
});
The form
<form class="rate-game">
<input type="radio" name="star" class="star {split:2}" value="0.5">
<input type="radio" name="star" class="star {split:2}" value="1">
... until 10
</form>
Any ideas what's causing the function to fire 10 times? If I remove the document.ready function, nothing happens, and the existing rating is not selected.