I am using the Raty Rating plug-in for jQuery in a webpage as seen below in, my issue is that when I add a comment with my code I can't get the rating as the rating code is generated on the fly by the jQuery code, I assume this is a delegation issue but unsure where to put my comment form submission code to allow it to get the rating value!?
HTML:
<form action="#" method="post" id="comment">
<div>
<p>Your comment: </p>
<script>
$(document).ready(function() {
// Generates the Raty Rating code below
$(".rating").raty({
hints: ['Poor', 'Fair', 'Good', 'Very Good', 'Excellent'],
path: "media/images/",
size: 24
});
});
</script>
<div class="rating"></div>
</div>
<textarea name="message" id="message"></textarea>
<input type="hidden" value="104" name="tid" id="tid">
<button type="submit">Add Comment</button>
</form>
Code generated by raty rating:
<div class="rating" style="cursor: pointer; width: 140px;">
<img src="media/images/star-off.png" alt="1" title="Poor">
<img src="media/images/star-off.png" alt="2" title="Fair">
<img src="media/images/star-off.png" alt="3" title="Good">
<img src="media/images/star-off.png" alt="4" title="Very Good">
<img src="media/images/star-off.png" alt="5" title="Excellent">
<input type="hidden" name="score">
</div>
script.js
$("#comment").on("click", "button", function(e)
{
e.preventDefault();
var tid = $('#comment #tid').val();
var rating = $('#comment #score').val();
var comment = $('#comment #message').val();
alert(tid+"\n"+rating+"\n"+comment);
});
Made it clear as to what the code is doing at present.