views:

287

answers:

1

Hi, I'm using the Starbox plugin on my website and I want to post the vote value when the visitor votes using AJAX.. I read the plugin documentation and tutorials and it's possible using a function like this:

function myOnRate(element, memo) {
  new Ajax.Request('savestar.php', {
    parameters: memo,
    onComplete: function(xhr) {
      // optional callback
    }
  });
}

Now I do know PHP but I don't really know javascript or Prototype and I need help with this function.

I know that the 'element' parameter is the ID of the rater and that savestar.php is the external php file that will be called using AJAX.. but beside that I have no idea what to do with this...

I want to send the vote value to savestar.php and then I will get the the value using the POST method and insert it into database. I will also need the 'element' to be sent so I can identify the rater..

Anyone?? Thanks!!

A: 

Well.... I find the solution myself so here it is:

<script language='javascript' type='text/javascript'>

      function saveStar(event) {
          new Ajax.Request('savestar.php', {
       parameters: event.memo,
       onComplete: function(xhr) {
           // optional callback
       }
          });
      }

      // observe just one
      document.observe('dom:loaded', function() { // once the DOM is loaded
          $('elementID').observe('starbox:rated', saveStar);
      });

      new Starbox('elementID', 8, { indicator: 'Rating: #{average} (#{total} votes)', total: 2 });

         </script>

If you are reading this and just don't get it just send me a message.

Jonathan