Loading ...
Sorry, an error occurred while loading the content.

problem with addlistener disappearing on tabview refresh

Expand Messages
  • estbiostudent
    hello all, I m having a problem with an addListener event listener disappearing or rather no longer sensing the event after a tabview reload. the datasrc
    Message 1 of 1 , Apr 29, 2007
    • 0 Attachment
      hello all,

      I'm having a problem with an addListener event listener disappearing
      or rather no longer sensing the event after a tabview reload. the
      datasrc returns html that includes a div with a unique id. the
      listener picks up click on this div and then fires a dialog box, and
      reloads the tabview. This works great the first time around, but once
      the tab reloads the addlistener event doesn't trigger again. I'm
      currently thinking this is becuase the reload recreates the div and
      the id again, and even though it's the same id, the dom isn't
      registering it again correctly. i've modified the code of the dynamic
      load example to demonstrate as the actual code is kind of messy.
      i've also tried adding an event handler for the reloading of the tab
      attempting to reestablish the event listener on the div in the tab.
      this didn't work either.. example of this provided below main code.
      any help is greatly appreciated

      --MAIN CODE--
      <script type="text/javascript">
      YAHOO.example.init = function(docnum,fnum) {
      var tabView = new YAHOO.widget.TabView({id: 'demo'});

      tabView.addTab(new YAHOO.widget.Tab({
      label: fnum,
      content: '<div id ="goof1">test</div>',
      active: true
      }));

      tabView.addTab(new YAHOO.widget.Tab({
      label: 'lorem',
      dataSrc: 'php/nonsense.php?type=para',
      cacheData: true /* only load once */

      }));

      var handleClick = function() {
      alert('You've clicked!');
      tabView.getTab(0).refresh();
      };

      YAHOO.util.Event.on('goof1','click',handleClick);

      YAHOO.util.Event.onContentReady(docnum, function() {
      tabView.appendTo(docnum);
      });

      };
      </script>
      <script type="text/javascript">
      YAHOO.example.init('doc2','form2');
      </script>


      <div id="doc2">
      <h1>TabView Example - Dynamically Loading Content</h1>
      <p>This example demonstrates how to load tab content dynamically.</p>

      </div>

      --SAMPLE RELOAD ADD LISTENER--
      tabView.getTab(0).on('load', function(){
      YAHOO.util.Event.onContentReady('goof1', function(){
      YAHOO.util.Event.on('goof1','click',handleClick,this);
      });
      });
    Your message has been successfully submitted and would be delivered to recipients shortly.