Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Need help with java script - next button on banner not working right

Need help with java script - next button on banner not working right

Scheduled Pinned Locked Moved Web Development
javascripthelpquestioncsharpjava
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Grapes R Fun
    wrote on last edited by
    #1

    :(( Hi Guys, I have incorporated this javascript banner news flash within my .net application, that works fine as it rotates through the news items. End users have recently asked for a next button/link that would immediately display the next item without them having to wait a few seconds. Now, the problem is that when I click on the next button, it doesn't display the next item right away, then the news items start to rotate faster and faster as I click the next button over and over... here is the layout of my silly js: function DisplayBanner(result, context) { ...get xml representation of banner items ...assign variables loop(); } function loop() { ...go through displaying one banner item ...increment banner index setTimeout('loop()', 10000); } function nextBanner() { ...increment banner index loop(); } My next button calls the nextBanner() function while the DisplayBanner() function is called on page load. Could someone please-please-please tell me what is it that Im doing wrong? Thanks for all/any help :-) Nila

    G 1 Reply Last reply
    0
    • G Grapes R Fun

      :(( Hi Guys, I have incorporated this javascript banner news flash within my .net application, that works fine as it rotates through the news items. End users have recently asked for a next button/link that would immediately display the next item without them having to wait a few seconds. Now, the problem is that when I click on the next button, it doesn't display the next item right away, then the news items start to rotate faster and faster as I click the next button over and over... here is the layout of my silly js: function DisplayBanner(result, context) { ...get xml representation of banner items ...assign variables loop(); } function loop() { ...go through displaying one banner item ...increment banner index setTimeout('loop()', 10000); } function nextBanner() { ...increment banner index loop(); } My next button calls the nextBanner() function while the DisplayBanner() function is called on page load. Could someone please-please-please tell me what is it that Im doing wrong? Thanks for all/any help :-) Nila

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      If you call the loop() function more than once, you will start another loop that runs along side the one that was started initially. Each time you call the loop() function you add another loop, that's why the items rotate faster and faster. I would suggest that you add a counter to the loop and fire it a lot more often. That way you can just zero the counter to make it skip to the next item:

      var counter;

      function DisplayBanner(result, context) {
      ...get xml representation of banner items
      ...assign variables
      counter = 100;
      loop();
      }

      function loop() {
      counter--;
      if (counter <= 0) {
      ...go through displaying one banner item
      ...increment banner index
      counter = 100;
      }
      window.setTimeout('loop()', 100);
      }

      function nextBanner() {
      counter = 0;
      }

      --- b { font-weight: normal; }

      G 1 Reply Last reply
      0
      • G Guffa

        If you call the loop() function more than once, you will start another loop that runs along side the one that was started initially. Each time you call the loop() function you add another loop, that's why the items rotate faster and faster. I would suggest that you add a counter to the loop and fire it a lot more often. That way you can just zero the counter to make it skip to the next item:

        var counter;

        function DisplayBanner(result, context) {
        ...get xml representation of banner items
        ...assign variables
        counter = 100;
        loop();
        }

        function loop() {
        counter--;
        if (counter <= 0) {
        ...go through displaying one banner item
        ...increment banner index
        counter = 100;
        }
        window.setTimeout('loop()', 100);
        }

        function nextBanner() {
        counter = 0;
        }

        --- b { font-weight: normal; }

        G Offline
        G Offline
        Grapes R Fun
        wrote on last edited by
        #3

        Thanks Guffa, it worked like a charm!!! :-D

        Nila

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups