Introduction
Rating controls are widely used in modern web sites to rate the product, blog, articles and so on. In this blog, you will learn how to implement the kendo rating control using JQuery and how to fetch the values from the control, based on the selection.
KendoRating.html
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.3.1023/styles/kendo.default-v2.min.css" />
-
- <script src="https://kendo.cdn.telerik.com/2019.3.1023/js/jquery.min.js"></script>
- <script src="https://kendo.cdn.telerik.com/2019.3.1023/js/kendo.all.min.js"></script>
-
- </head>
- <body>
- <div id="example">
- <div class="k-content">
- <h4>Rating </h4>
- <input id="rating" name="rating" style="width: 100%;" />
- </div>
-
- <div class="box">
- <h4>Result</h4>
- <div>
- Old value: <label id=lblOldValue />
- </div>
- <div>
- New Value: <label id=lblNewValue />
- </div>
- </div>
-
- <script>
- $(document).ready(function () {
- $("#rating").kendoRating({
- min: 1,
- max: 5,
- value: 3,
- change: onChange,
- });
-
- function onChange(e) {
- $("#lblOldValue").text(e.oldValue)
- $("#lblNewValue").text(e.newValue)
- }
- });
- </script>
- </div>
-
-
- </body>
- </html>
In the above code, you can see how Kendo Rating control is initialized with some properties:
- min – defines the minimum rating
- max – defines the maximum rating
- value – default rating value
- change- the change event which will be captured when there is a change in the rating
In a change event, we are capturing the old and new values from the control and it will be bound with label control
Summary
We have seen how to implement the kendo rating control using JQuery, and working with a change event in regards to rating control.