Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Baby's Question: function getting hung up???

    ok, a simple btnHandler function but when it comes around its stalls:

    Code:
    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!!

  • #2
    New Coder
    Join Date
    May 2009
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I figured it out, i should have been resetting it to 2 not to 1.

  • #3
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    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
    Code:
    var btnCounterProjects = 1;
    function btnHandlerProjects() {
    	if (btnCounterProjects++ % 2) showProjects();
    	else hideProjects();
    }
    will do.

  • Users who have thanked venegal for this post:

    tunkKid (06-03-2009)

  • #4
    New Coder
    Join Date
    May 2009
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts
    "Your script is overly convoluted." Is an understatement!!

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •