...

View Full Version : Baby's Question: function getting hung up???



tunkKid
06-03-2009, 09:26 PM
ok, a simple btnHandler function but when it comes around its stalls:


var btnCounterProjects = 1;
function btnHandlerProjects() {
if(btnCounterProjects == 1) {
showProjects();
btnCounterProjects++;
console.debug(btnCounterProjects);
} else if(btnCounterProjects < 3) {
hideProjects();
btnCounterProjects++;
console.debug(btnCounterProjects);
} else if(btnCounterProjects < 4) {
showProjects();
btnCounterProjects=1;
console.debug(btnCounterProjects);
}
}

So it will go thru great the first time but when it gets reset to 1, then incremented to 2, it doesn't then do the hideProjects() function or increment?? It will remain a 2, then work when you click it again?? so you have to click it twice for it to work?? Any suggestions?

Thanks!!

tunkKid
06-03-2009, 09:49 PM
I figured it out, i should have been resetting it to 2 not to 1.

venegal
06-03-2009, 09:57 PM
Well, not really. Your script is overly convoluted. It sounds to me like you just want to call showProjects and hideProjects alternately. If that's the case, something simple like

var btnCounterProjects = 1;
function btnHandlerProjects() {
if (btnCounterProjects++ % 2) showProjects();
else hideProjects();
}

will do.

tunkKid
06-03-2009, 10:54 PM
"Your script is overly convoluted." Is an understatement!!

Thanks, I appreciate your help and ability to make my code more efficient!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum