Question

I'm using late-binding to assign onClick events to checkboxes (styled as dots). My first assignment [located at https://github.com/farfromunique/vampirrePoints/blob/master/events.js#L264 ] goes perfectly, and reacts as expected - all dots have this as their onClick:

/* https://github.com/farfromunique/vampirrePoints/blob/master/main.js#L440 */
allDots[i].onclick = function() { 
    if (this.checked) {
        decrementCounter(1);
    } else {
        incrementCounter(1);
    };
}

However, when Step11() is triggered, and freebieDotSetup() is called, only some of the checkboxes get their onClicks updated. Specifically, sta1, sta2, sta3, sta4, sta5 (possibly others, too) keep their initial value.

I have tried putting console.log() statements in during the assignment process, and it looks like the assignment happens, but it doesn't "stick". Why doesn't this work?

Code reference (whole site): https://github.com/farfromunique/vampirrePoints

By request, a non-working JSFiddle: http://jsfiddle.net/farfromunique/mS4Lp/

Note: the menu is on the wrong side, doesn't advance properly, and none of the "dots" (checkboxes) are clickable, so functionality is not testable. I strongly suspect that my code is not cross-browser compatible, but that isn't a priority for me (yet).

Was it helpful?

Solution

The solution: In the function freebieDotSetup(), I was doing this:

for (i=0;i<attributeDots.length;i++) {
    attributeDots[i] = allDots[i];
}
...
for (i=0;i<abilityDots.length;i++) {
    abilityDots[i] = allDots[i+attributeDots.length];
}
...
for (i=0;i<disciplineDots.length;i++) {
    disciplineDots[i] = allDots[i+abilityDots.length];
}
...

Since I was using the previous group's length, it would occasionally overwrite the previous values (due to groups being shorter). I corrected this with this:

startPos = startPos + attributeDots.length;

for (i=0;i<abilityDots.length;i++) {
    abilityDots[i] = allDots[i+startPos];
}

Adding the previous group's length to startPos each time. Making this change resolved my issue.

... But the JSFiddle is totally busted, still.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top