Reputation: 86
for (i = 1; i < total.length; i++) {
$("div.category:nth-of-type(" + i + ") ul.qItem li :input[type=radio]:checked").each(function() {
total[i] += parseInt($(this).val());
$("div.category:nth-of-type(" + i + ") div.report div.scorebox").html(total[i] + " / 15");
});
if (total[i] > 11) {
$("div.category:nth-of-type(" + i + ") div.t12").toggle();
$("div.category:nth-of-type(" + i + ") div.report div.scorebox").css("color", "green");
$("div.category:nth-of-type(" + i + ") div.report span.opinion").html(high).css("color", "green");
} else if (total[i] < 7) {
$("div.category:nth-of-type(" + i + ") div.t6").toggle();
$("div.category:nth-of-type(" + i + ") div.report div.scorebox").css("color", "#900");
$("div.category:nth-of-type(" + i + ") div.report span.opinion").html(low).css("color", "#900");
} else {
$("div.category:nth-of-type(" + i + ") div.t711").toggle();
$("div.category:nth-of-type(" + i + ") div.report div.scorebox").css("color", "orange");
$("div.category:nth-of-type(" + i + ") div.report span.opinion").html(medium).css("color", "orange");
}
}
This for loop should iterate through 5 divs and sum the values of the input radio buttons selected in each of them. Then it should output the score in each of the 5 categories in a scorebox. Depending on 3 ranges, it should then output a different opinion on their performance (low, medium, high), color the text red, orange, or green, and toggle the visibility of some text offering advice (t6, t711, t12). Unfortunately it doesn't seem to be able to put the score in the scorebox or select the correct text to show. Can anyone suggest how to have this script operate on each div in turn?
Upvotes: 2
Views: 208
Reputation: 5368
jQuery has this built in.
$('selector').each(function(index, element) {
});
Upvotes: 4