I have a list of items on a page dynamically generated - I can get the $itemid of each one easily enough.
I am trying to setup a vote for each one but I can't make the instances different enough for the instances of the vote links not to get confused with each other, and the page is trying as you would expect, to post all the items to my vote.php page
<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>
thisis bound to the DOM element involved. Thus, as long as your PHP code is putting distinct "id" values, and storing other information in "data-" attributes, the event handler can form the appropriate HTTP request.