Multiple functions on window.onload

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lilOlMe
    New Member
    • May 2007
    • 74

    Multiple functions on window.onload

    Hi there!

    I'm developing some crazy Tab Control in .NET that uses JavaScript.

    A particular JavaScript method needs to be called during the window.onload event in order to initialize my Tab Control.

    The thing is that there can be more than one Tab Control on the page....and each one must be initialized during the window.onload event.

    Adding the JavaScript function call responsible for initializing a particular Tab Control to the function that the window.onload calls is impossible using .NET (I've tried to do this for 4 days now...)

    For Example:
    This is not possible to do from a .NET standpoint:
    [code=javascript]

    <script type="text/javascript">
    <!--
    window.onload = function() {

    /*This Is Not Possible*/
    eval(TabControl 1_intializeTabb edControls());
    eval(TabControl 2_intializeTabb edControls());
    eval(TabControl 3_intializeTabb edControls());
    /*.............. .......*/
    }// -->
    </script>
    [/code]

    This is possible to do from a .NET standpoint but obviously won't work in JavaScript:
    [code=javascript]
    <script type="text/javascript">
    <!--window.onload = function() {eval(TabContro l1_intializeTab bedControls()); }//-->
    </script>

    <script type="text/javascript">
    <!--window.onload = function() {eval(TabContro l2_intializeTab bedControls()); }//-->
    </script>

    <script type="text/javascript">
    <!--window.onload = function() {eval(TabContro l3_intializeTab bedControls()); }//-->
    </script>
    [/code]

    Basically I'd like to call the window.onload more than once...but this isn't possible...so I'm open to any other suggestions...

    Does anyone have any suggestions on how to do this?

    Thanks for your time

    -lilolme
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Try using addEventListene r (W3C standard) and attachEvent (IE). See this article (the events part). Also see this link for an explanation.

    PS. changed the thread title slightly.
    Last edited by acoder; Sep 5 '07, 06:01 PM. Reason: Added link

    Comment

    • lilOlMe
      New Member
      • May 2007
      • 74

      #3
      Originally posted by acoder
      Try using addEventListene r (W3C standard) and attachEvent (IE). See this article (the events part). Also see this link for an explanation.

      PS. changed the thread title slightly.
      Acoder, you're a lifesaver!!
      Thank you so much for that quicksmode link!
      You've helped me immensely!
      Every thing's working well in browsers that are not IE :):)

      IE will load the page properly ...except that for some reason I'm getting a "Type Mismatch" error. The line number that IE says the error occur on just contains a <tr>...and the vagueness of the error is not helping me at all.

      [code=javascript]
      <script type="text/javascript">
      <!--
      if(window.attac hEvent){
      window.attachEv ent("onload",Ta bControl1_intia lizeTabbedContr ols());
      }else{
      window.addEvent Listener("load" ,TabControl1_in tializeTabbedCo ntrols(),false) ;
      }
      // -->
      </script>

      <script type="text/javascript">
      <!--
      if(window.attac hEvent){
      window.attachEv ent("onload",Ta bControl2_intia lizeTabbedContr ols());
      }else{
      window.addEvent Listener("load" ,TabControl2_in tializeTabbedCo ntrols(),false) ;
      }
      // -->
      </script>
      [/code]

      Do you have any insight as to why this might be occurring?
      Thank you for being so patient with me :) JavaScript is not one of my strong points.

      -LilOlMe

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Remove the parentheses when attaching/adding event listeners:
        [code=javascript]
        if(window.attac hEvent){
        window.attachEv ent("onload",Ta bControl1_intia lizeTabbedContr ols);
        }else{
        window.addEvent Listener("load" ,TabControl1_in tializeTabbedCo ntrols,false);
        }[/code]If that doesn't work, show the code for the tab control function.

        Comment

        • lilOlMe
          New Member
          • May 2007
          • 74

          #5
          Originally posted by acoder
          Remove the parentheses when attaching/adding event listeners:
          [code=javascript]
          if(window.attac hEvent){
          window.attachEv ent("onload",Ta bControl1_intia lizeTabbedContr ols);
          }else{
          window.addEvent Listener("load" ,TabControl1_in tializeTabbedCo ntrols,false);
          }[/code]If that doesn't work, show the code for the tab control function.
          Thanks Again!

          I removed the () and everything works perfectly now :)

          Wish I had asked my question earlier!


          -LilOlMe

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Glad you got it working. Post again anytime should you hit some problem.

            Comment

            Working...