By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,478 Members | 1,833 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,478 IT Pros & Developers. It's quick & easy.

Multiple functions on window.onload

P: 74
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:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <script type="text/javascript">
  3. <!--
  4. window.onload = function() {
  5.  
  6. /*This Is Not Possible*/
  7. eval(TabControl1_intializeTabbedControls());
  8. eval(TabControl2_intializeTabbedControls());
  9. eval(TabControl3_intializeTabbedControls());
  10. /*.....................*/
  11. }// -->
  12. </script>
  13.  
This is possible to do from a .NET standpoint but obviously won't work in javascript:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--window.onload = function() {eval(TabControl1_intializeTabbedControls());}//-->
  3. </script>
  4.  
  5. <script type="text/javascript">
  6. <!--window.onload = function() {eval(TabControl2_intializeTabbedControls());}//-->
  7. </script>
  8.  
  9. <script type="text/javascript">
  10. <!--window.onload = function() {eval(TabControl3_intializeTabbedControls());}//-->
  11. </script>
  12.  
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
Sep 5 '07 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
Try using addEventListener (W3C standard) and attachEvent (IE). See this article (the events part). Also see this link for an explanation.

PS. changed the thread title slightly.
Sep 5 '07 #2

P: 74
Try using addEventListener (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.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3. if(window.attachEvent){
  4.     window.attachEvent("onload",TabControl1_intializeTabbedControls());
  5. }else{    
  6.     window.addEventListener("load",TabControl1_intializeTabbedControls(),false);
  7. }
  8. // -->
  9. </script>
  10.  
  11. <script type="text/javascript">
  12. <!--
  13. if(window.attachEvent){
  14.     window.attachEvent("onload",TabControl2_intializeTabbedControls());
  15. }else{   
  16.     window.addEventListener("load",TabControl2_intializeTabbedControls(),false);
  17. }
  18. // -->
  19. </script>
  20.  
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
Sep 6 '07 #3

acoder
Expert Mod 15k+
P: 16,027
Remove the parentheses when attaching/adding event listeners:
Expand|Select|Wrap|Line Numbers
  1. if(window.attachEvent){
  2.     window.attachEvent("onload",TabControl1_intializeTabbedControls);
  3. }else{   
  4.     window.addEventListener("load",TabControl1_intializeTabbedControls,false);
  5. }
If that doesn't work, show the code for the tab control function.
Sep 6 '07 #4

P: 74
Remove the parentheses when attaching/adding event listeners:
Expand|Select|Wrap|Line Numbers
  1. if(window.attachEvent){
  2.     window.attachEvent("onload",TabControl1_intializeTabbedControls);
  3. }else{   
  4.     window.addEventListener("load",TabControl1_intializeTabbedControls,false);
  5. }
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
Sep 6 '07 #5

acoder
Expert Mod 15k+
P: 16,027
Glad you got it working. Post again anytime should you hit some problem.
Sep 6 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.