javascript - JS only updates one element with same ID on onclick response -


this simple problem, i'm not familiar js. i'm using wordpress comment rating plugin display 2 loops of comments - 1 sorted "thumbs" rating, , second standard order.

the problem:

when thumb clicked next comment in standard section vote added comment in rating section - since it's called first in code on site. standard section rating box not being updated until page refresh.

what expected: when vote clicked, rating same comment should updated in both rating , standard loops sectons.

code:

function ckratingcreatexmlhttprequest(){ var xmlhttp = null; try {     // moz supports xmlhttprequest. ie uses activex.     // browser detction bad. object detection works browser     xmlhttp = window.xmlhttprequest ? new xmlhttprequest() : new activexobject("microsoft.xmlhttp"); } catch (e) {     // browser doesn’t support ajax. handle want     //document.getelementbyid("errormsg").innerhtml = "your browser doesnt support xmlhttprequest.";     // won't ordinary users.  turned off     // alert("your browser not support xmlhttprequest object!"); } return xmlhttp; } var ckratingxhr = ckratingcreatexmlhttprequest();   function ckratingkarma(id, action, path, imgindex){ ckratingxhr.open('get', 'http\://'+ path +'ck-processkarma.php?id='+ id +'&action='+ action +'&path='+ path +'&imgindex='+imgindex); ckratingxhr.onreadystatechange = ckratinghandleresponse; ckratingxhr.send(null); }  function ckratinghandleresponse(){ if(ckratingxhr.readystate == 4){     var response = ckratingxhr.responsetext.split('|');            if(response[0] == 'done'){         if(response[1]){             //changes thumbs dull gray , disable action             if (response[4] == 'down') {               if ( document.getelementbyid("down-"+response[1]) != null ) {                    document.getelementbyid("down-"+response[1]).src = "http://"+response[3]+'images/'+response[6]+'checkmark.png';                }             }             else {               if ( document.getelementbyid("down-"+response[1]) != null ) {                   document.getelementbyid("down-"+response[1]).src = "http://"+response[3]+'images/'+response[6]+'gray_down.png';               }             }             if ( document.getelementbyid("down-"+response[1]) != null ) {                document.getelementbyid("down-"+response[1]).onclick    = '';             }             if (response[4] == 'up') {                if ( document.getelementbyid("up-"+response[1]) != null ) {                   document.getelementbyid("up-"+response[1]).src   = "http://"+response[3]+'images/'+response[6]+'checkmark.png';                }             }             else {                if ( document.getelementbyid("up-"+response[1]) != null ) {                   document.getelementbyid("up-"+response[1]).src   = "http://"+response[3]+'images/'+response[6]+'gray_up.png';                }             }             if ( document.getelementbyid("up-"+response[1]) != null ) {                document.getelementbyid("up-"+response[1]).onclick      = '';             }             //update karma number display             if(!response[2]){                 alert("response has no value");             }             var karmanumber = response[2];             //the below line commented out because there no karma number atm.             if (document.getelementbyid("karma-"+response[1]+"-"+response[4]) != null) {                document.getelementbyid("karma-"+response[1]+"-"+response[4]).innerhtml = karmanumber;             }             // deal single value total             if (document.getelementbyid("karma-"+response[1]+"-total") != null) {                document.getelementbyid("karma-"+response[1]+"-total").innerhtml = response[5];             }         } else {             alert("wtf ?");         }     }     else if(response[0] == 'error')     {         var error = 'error: '+response[1];         alert(error);     } else {        /*  causes unnecessary error messages when icon         *  double clicked.            alert("reponse: "+response[0]);         alert("karma not changed, please try again later.");         */     } } }  var crtogglecomment = 0;  function crswitchdisplay(id) { if (crtogglecomment % 2 == 0) { crshowdiv(id); } else { crhidediv(id); } crtogglecomment++; }  // hide <div id='a2' style="display:none;"> tagged div id blocks function crhidediv(id) { //safe function hide element specified id if (document.getelementbyid) { // dom3 = ie5, ns6     document.getelementbyid(id).style.display = 'none'; } else {     if (document.layers) { // netscape 4         document.id.display = 'none';     }     else { // ie 4         document.all.id.style.display = 'none';     } } }  // show <div id='a2' style="display:none;"> tagged div id blocks // <a href="javascript:crshowdiv('a2');">show a2</a>  function crshowdiv(id) { //safe function show element specified id  if (document.getelementbyid) { // dom3 = ie5, ns6     document.getelementbyid(id).style.display = 'block'; } else {     if (document.layers) { // netscape 4         document.id.display = 'block';     }     else { // ie 4         document.all.id.style.display = 'block';     } } } 

in dom id must unique, cannot have 2 elements same id and, title suggest, in case getelementbyid function took first.

you use notation id-standard, id-rated or use jquery , selectors


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -