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.
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function()
- {
- $(".submitVote a").click(function()
- {
- var ID = <?php echo $itemid;?>;
- var add = 1;
- var votedby = <?php echo $usr_id ;?>;
- var rating = <?php echo $ratings;?>
- var queryString = 'id='+ ID +'&votedby='+votedby +'&add='+add +'&rating='+rating;
- $("#vote").text(rating+1);
- $.ajax({
- type: "POST",
- url: "vote.php",
- data: queryString,
- cache: false,
- success: function(html)
- {
- $(".submitVote").html('<p style="margin:1px;padding:0px;"></p>');
- $("#greet").html("Thanks for voting!");
- $("#greet").delay(500).fadeOut(5000);
- }
- });
- });
- });
- </script>
- <div id="<?php echo $itemid;?>" style="width:350px;">
- <span class="submitVote" >
- <p style="margin:1px;padding:0px;">
- Submit your <a href="#">vote</a>
- </p>
- </span>
- <div id="voteBox">
- <div id="vote<?php echo $itemid;?>"> <?php echo $ratings;?> </div>
- <span style="color:#fae240;">votes</span>
- </div>
- <div id="greet" style="padding-left:65px;"></div>
- </div>