Sunday, 13 March 2016

Star rating using jquery


Requirements

1)Jquery
2)star rating plugin

 Download it from here
https://www.dropbox.com/sh/1mguiv1l4w6afdx/AAClxTcd0FWPFJuBWeVl5oABa?dl=0

Project Structure




Index.jsp

<html>
<head>
<link rel="stylesheet" href="resources/rating/jquery.rateyo.css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Rating</title>
</head>
<body>
    <div id="id-showStar"></div>
    <span class="counter" id="counter"></span>   
    <button id="id-showReading" name="name-showReading" onclick="showRating()">Show Rating</button>
    <div id="id-showRating"></div>
</body>
<script src="resources/jquery/jquery-2.1.4.min.js"></script>
<script src="resources/rating/jquery.rateyo.js"></script>
<script src="resources/customjs.js"></script>
</html>


customjs.js


$(document).ready(function() {
   
    $("#id-showStar").rateYo({
        onChange : function(rating, rateYoInstance) {
            $(this).next().text(rating);
        }
    });

});

function showRating() {   
   
    var getRating = document.getElementById("counter").innerHTML;
    $("#id-showRating").rateYo({
        rating : getRating
    });
   
}
 

No comments:

Post a Comment