1

I am trying to get value from Jrate Plugin for example when the using click on 3rd start the value should i get should must be 3.and i can get it on using jRate onSet option Here is my HTML

<div id="jRate"></div>

And My Javascript is

  $("#jRate").jRate({
        onSet: function(rating) {
                   alert("Selected Rating: "+rating);
             }
    });

but i dont want to get the value on onSet function i want value when user click on save button just like how we get value from inout box

$('#inputbox').val(); 

Is their any way i can get value like this..

usama
  • 797
  • 1
  • 11
  • 44

1 Answers1

3

One way is to set a custom attribute. You can do this on the #jRate element

$("#jRate").jRate({
        onSet: function(rating) {
                   $("#jRate").attr("data-rating", rating);
             }
    });

then, later in the click handler

$("button").click(function(){
    var rating = $("#jRate").attr("data-rating");
});
AmmarCSE
  • 29,061
  • 5
  • 39
  • 52
  • var rating = $("#jRate").attr("data-rating"); is giving me undefined in the console. – usama May 23 '15 at 11:48
  • @usama, did you set the rating first? – AmmarCSE May 23 '15 at 11:49
  • yes i set the ratting first the problem is the jRate is SVG based... so it is showing me undefined. – usama May 23 '15 at 11:50
  • @usama, can you reproduce this in a fiddle? – AmmarCSE May 23 '15 at 11:53
  • can you help me how should i use $(document) with JRate plugin with this code $(".jRate").jRate({ onSet: function(rating) { alert(rating) } }); – usama May 23 '15 at 18:39
  • No @AmmarCSE kindly look at my this question i have explained this better on my question http://stackoverflow.com/questions/30416417/jquery-is-not-working-on-newly-added-elements-to-the-dom-with-plugin-like-jrate – usama May 23 '15 at 20:12
  • The code which you have given me is working totaly fine when page is loaded by default but it is not working i append the div through jquery using dom... – usama May 23 '15 at 20:14
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/78611/discussion-between-ammarcse-and-usama). – AmmarCSE May 23 '15 at 20:15