Trying to get multiple copies of the code to work

Trying to get multiple copies of the code to work

I am trying to get the code working - several instance of the code on the same page - ie there needs to be one one instance of the code for every item that needs a vote.

Unfortunately I cannot make the code 'different enough' for each item. I know the $itemid for each item, but how does I pass this to the code below so the the vote button refers to the item it is next to.

At the moment, if I click on any vote the code tries to apply the vote across every item on the page, then fails and refreshes all vote buttons.

  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  2. <script type="text/javascript">
  3.     $(document).ready(function()
  4.     {
  5.         $(".submitVote a").click(function()
  6.         {
  7.             var ID = <?php echo $itemid;?>;
  8.             var add = 1;
  9.             var votedby = <?php echo $usr_id ;?>;
  10.             var rating = <?php echo $ratings;?> 

  11.             var queryString = 'id='+ ID +'&votedby='+votedby +'&add='+add +'&rating='+rating;
  12.             $("#vote").text(rating+1); 

  13.                 $.ajax({
  14.                 type: "POST",
  15.                 url: "vote.php",
  16.                 data: queryString,
  17.                 cache: false,
  18.                 success: function(html)
  19.                 {

  20.                     $(".submitVote").html('<p style="margin:1px;padding:0px;"></p>');
  21.                     $("#greet").html("Thanks for voting!");
  22.                     $("#greet").delay(500).fadeOut(5000);

  23.                 }
  24.                 });
  25.         });
  26.     });
  27. </script>

  28.     <div id="<?php echo $itemid;?>" style="width:350px;">
  29.         <span class="submitVote" >
  30.             <p style="margin:1px;padding:0px;">
  31.                 Submit your <a href="#">vote</a>
  32.             </p>
  33.         </span>
  34.         <div id="voteBox">
  35.             <div id="vote<?php echo $itemid;?>"> <?php echo $ratings;?> </div>
  36.             <span style="color:#fae240;">votes</span>
  37.         </div> 
  38.         <div id="greet" style="padding-left:65px;"></div>
  39.     </div>