Cassie Mod

Cassie Mod

  • NA
  • 488
  • 71.1k

foreach loop doesnt work how i was suspecting

Feb 4 2016 11:38 AM
HI,
Ive got the following question. I've got several partial views. Ech partial view has a value CollectorValue.Based on the Collector Value the partialview schould get the background color red (failed) or green( completed). However for some reason it is only looking at the first item. So when that is failed all the partial views turn on red and when that is green all the partial views turn on green instead of looking at each CollectorValue of the partialview and make it green or red. My question is how can i fix this (please send me the good javascript code)? that it really checks of value CollectorValue of all the partialviews instead of only the first.
 
Here is my script:

  1. $("#conditionalOn").click(function () {  
  2.     var countCompleted = 0;  
  3.     var countFailed = 0;  
  4.     $('#collector tr').each(function () {  
  5.         var waarde = $("#collectorValue").text()  
  6.         if (waarde == "Failed") {  
  7.             $(this).css('backgroundColor''#f76e6e');  
  8.             countFailed = countFailed + 1;  
  9.         }  
  10.         if (waarde == "Completed") {  
  11.             $(this).css('backgroundColor''#99faa0');  
  12.             countCompleted = countCompleted + 1;  
  13.         }  
  14.     });  
  15.     event.preventDefault();  
  16. }) ; 

 
 

Answers (9)