I created an HTML rubric that allows a user to select a cell and have it add up the earned points versus the points possible. Right now, I have a function that only allows one td per row to be selected. When a cell is selected, it adds the points to a variable. The issue is, when I change the selection for the row, it just adds the new selection on top of the variable, it doesn't subtract and replace the value.
For example, if I had an 8 point selection made, but change it to 6, instead of the variable value being 6, it adds the 6 to the 8.
The function I have to add up the points is as follows:
jQuery('#ldrm-rubric-loaded td.choice').click(function () {
// Obtain points earned
var ndx = jQuery(this).index() + 1;
var target = jQuery('#ldrm-rubric-loaded thead tr.points th:nth-child('+ndx+')').html();
if(!isNaN(target) && target.length != 0) {
pointsEarned += parseFloat(target);
}
jQuery('#ldrm-points-earned').html('Points Earned: '+pointsEarned);
alert(pointsEarned);
});
http://jsfiddle.net/f6u2pjgu/1/
Any ideas on how I could alter the function to replace the value instead of adding on to it?