I am having a list of values inside a loop. I need to turn all those values into exact 5 star rating. I have searched a lot, but i cant get the exact answer what i need.
I have tried this: Turn a number into star rating display using jQuery and CSS
But it is working only for single value. Consider my code is like this:
<?php
$a=0;
while($a<5)
{
echo "<input type=text value=$a><br/>";
//need to display star rating here
$a=$a+1.2;
}
?>
its just for an example. I want to convert all the values in the textbox into a star rating. In my original code i am taking a loop of values from DB. Please help me to do this.
this code is working fine for single value.
<html>
<head>
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(function() {
$('p').html('<span class="stars">'+parseFloat($('input[name=amount]').val())+'</span>');
$('span.stars').stars();
});
$.fn.stars = function() {
return $(this).each(function() {
$(this).html($('<span />').width(Math.max(0, (Math.min(5, parseFloat($(this).html())))) * 16));
});
}
</script>
<style type="text/css">
span.stars, span.stars span {
display: block;
background: url(image/stars.png) 0 -16px repeat-x;
width: 80px;
height: 16px;
}
span.stars span {
background-position: 0 0;
}
</style>
</head>
<body>
<input type="text" name="amount" value="4" />
<p>
<span class="stars">2.4618164</span></p>
</body>
</html>
but i dont know how to do this for loop of values.