Dynamically set ''data-rateit-value''

Aug 19, 2014 at 3:22 AM
I need to set the value of an attribute to show 'x' amount of stars but need to run an event to my database to get the average and use that number?

here is this HTML with the 'data-rateit-value' attribute id like to modify dynamically.
<div id="randomtest" data-productid="randomtest" class="rateit" data-rateit-value=""></div>
i tried this just to modify it without an event to query the database and it didnt set it? so need some advise before i go on to including the event.
$('#randomtest').attr( 'data-rateit-value','4');
but once im able to i will be able to set it dynamically like i have made a basic demo of below? if not some further guidance would be much appreciated.
    url: 'currentvalue.php',
    data: { id: productID, value: value },
    type: 'POST',

    success: setCurrentValue

function setCurrentValue(data) {
    $('#randomtest').attr( 'data-rateit-value'.append(data));
thanks for any help
Aug 19, 2014 at 5:25 AM
Have a look at the online examples : http://www.radioactivethinking.com/rateit/example/example.htm Anyway to set a value in JS you would do: $('#abc').rateit('value', mynewvalue)
Aug 19, 2014 at 7:29 AM
Edited Aug 19, 2014 at 7:35 AM
oops i forgot to come back and post that i sorted it.

I am using this query to update when a rating is selected and when the page loads.
// show average star rating once rating has been click
        url: 'currentstars.php',
        data: { id: productID, value: value },
        type: 'POST',
        success: function(results) {
            $('.rateit').rateit('value', (results));
but not for quizzing a few people on stackoverflow who didn't i think became as confused as i was as to why it wasn't working lol.


thanks for thanks reply.