Ajax Poll - How to retrieve new score to the correct span id
I want to create an AJAX poll to rate comments. In each comment you can either thumbs up, or thumbs down by clicking on an image. I achieved that part. However, I don't know how to update the score with AJAX in the correct span.
document.getElementById ("response").innerHTML =xmlHttp.responseText;
That shows the result in <span id="response">new score</span>
I want the new score to be updated next to the thumbs up or thumbs down image, in the comment that was rated.
I generate the span tags like this:
<span id="response<?php echo $comment_id; ?>">I want the new score here</span>
If you don't know what the value of $comment_id is ahead of time, then the onclick event will have to pass this id to the AJAX code so that the AJAX code can send back the returned score to the proper place.
I don't know how to pass the id to AJAX with the onclick event. I'm not very good with JS.
Show the onclick event you're using now to invoke the AJAX process. Also show the HTML around where the onclick event is so that I can see the relationship between where the onclick is and where the response container is.
Originally Posted by yspa
<input type="image" id="heart" src="images/heart.png" onClick="ajaxFunction();" value="<?php echo $comment_id; ?>&mode=voteup" />
<span id="response<?php echo $comment_id; ?>
var myQuery = document.getElementById('heart');
OK, since $comment_id is also placed in the value for the INPUT element, then you can code your inline event attribute as follows to pass that to your function as an argument:
You'll just need to extract it for use in the getElementById method to obtain addressability to the response span.
and to extract it I would use one of the methods, such as split(delimiter), described in this page?
it works. Thanks so so much.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread