0

I'm using the jQuery Knob plugin https://github.com/aterrien/jQuery-Knob

Now, I've got the following jQuery Knob Initialization

loop
   <input type="text" value="<?php echo $score; ?>" class="circle-rating" data-entryid="<?php the_ID(); ?>">
endloop



$(function() {
    $(".circle-rating").knob({
            'min':0,
            'max':10,
            'step':1,
            'width':40,
            'height':40,
            'fgColor':"#F59B00",
            'inputColor':"#F59B00",
            'displayPrevious': true,
            'release' : function (v) { 

                var entry_id = $(this).attr('data-entryid');

                jQuery.post("/path/to/file/update_library_score.php", {v : v, entry_id : entry_id}, function(data) {
                    console.log(entry_id);
                    jQuery('#notification-general').html(entry_id);

                });
            }

    });
});

The main issue is that I have multiple knobs on the page. These knobs are actually in a loop with wordpress posts.

Anyway, each knob is attached to an ID and this ID changes as you go through the loop.

Now to be able to update the score I need two things the knob's value which I get from the release function and I also need the post_id which I can only get within the loop. So how can I get the post_id variable to this function?

Usually I can simply add a button or a link with a onclick="my_function(<?php echo $post_id; ?>) however, I can't do it with this. What's the best way of grabbing the $id that corresponds with this knob and passing it to the release function as a parameter?

Maaz
  • 4,193
  • 6
  • 32
  • 50
  • you could use custom attributes via `data-*` to he `.circle-rating` elements and access it via $(this).attr('data-*') in your release function. where * may be any string u want – Nouphal.M Dec 31 '13 at 11:01
  • @Nouphal.M I've updated my question with what you said (I think) but it doesn't seem to work. – Maaz Dec 31 '13 at 11:09
  • what does entry_id output?. check in console or alert the value and – Nouphal.M Dec 31 '13 at 11:11
  • @Nouphal.M fixed a syntax error and tried `console.log(entry_id);` as you can see in the updated question code and console returns `undefined`. – Maaz Dec 31 '13 at 11:13

1 Answers1

2

Try this in release function

alert(this.$.attr('data-entryid'));

See demo here

Nouphal.M
  • 6,304
  • 1
  • 17
  • 28
  • Yup, seems like `this.$.attr('data-entryid')` works instead of `$(this).attr('data-entryid')` – Maaz Dec 31 '13 at 11:25