tags:

views:

9

answers:

1

ajax-

xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("lblvoteup").innerHTML=xmlhttp.responseText;
//document.getElementById("lblvotedown").innerHTML=xmlhttp.responseText;
}
}

html-

<tr>                    
                <td ><img src="images/up.jpeg" style="border:none;" title="Like" 
                onclick="doVote('<?php echo $q_id; ?>','<?php echo $_SESSION['UserId']; ?>','up', '<?php echo $q_up; ?>')"></td>
                <td ><label id="lblvoteup"><?php echo $q_up;?></label></td>
                <td style="border-left:1px solid whitesmoke;"><img src="images/down.jpeg"  style="border:none;" title="Dislike" 
                onclick="doVote('<?php echo $q_id; ?>','<?php echo $_SESSION['UserId']; ?>','down', '<?php echo $q_down; ?>')"></td>
                <td ><label id="lblvotedown"><?php echo $q_down; ?></label></td>
            </tr>

problem is I dont want to write another ajax function to update lblvotedown.How can i check that which image is clicked in ajax function?

A: 

Hi,

It is simple, do the following process

1) let response Text contain the following type of data "down--10" or "up--11" (assuming you are currently getting the updated count of vote down or up)

2) split the data retrieved using the javascript code

var returns=xmlhttp.responseText.split("--");

3) use the following in the ajax function

xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
  var returns=xmlhttp.responseText.split("--");
  if(returns[0]=="up") 
  document.getElementById("lblvoteup").innerHTML=returns[1];
  else
  document.getElementById("lblvotedown").innerHTML=returns[1];
}
}

Hope helpful

srinivas