|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
how to use two "onLoad"
I have two JavaScript code for onLoad.
<body marginwidth="0" marginheight="0" style="margin: 0" onLoad="writeMenus()" onResize="if (isNS4) nsResizeHandler()"> How do I combine the above one and the following one: <body onLoad="javascript:startStatusScroller(statBarMsg);"> |
|
#2
|
|||
|
|||
|
RE: how to use two
you can do one of two things, first, you could include both function calls in the onload event,(seperated by a semicolon) or better yet, create a function that calls both functions and then call that from the onload event
|
|
#3
|
|||
|
|||
|
RE: how to use two
Couldn't you just do this?
<body marginwidth="0" marginheight="0" style="margin: 0" onLoad="writeMenus(); startStatusScroller(statBarMsg);" onResize="if (isNS4) nsResizeHandler();" > -edit- sorry blindeddie, hadn't refreshed the page so didn't see u had replied. Having an extra function to do this is pointless, unless you will call these two things in multiple places. |
|
#4
|
|||
|
|||
|
RE: how to use two
when I use javascript, I tend to use external javascript files that I share amongst all my pages, so it makes life easier for me to create a function that includes other function calls so that if I need to make a change to the function or add another function to an event, I only need to change it in one place. Hardly pointless from a coding and maintenance standpoint!
|
|
#5
|
|||
|
|||
|
RE: how to use two
I didn't atually look at what he was doing, just the syntax. It is likely that many of his pages will have the same body onLoad's, so obviously a function in a shared script would be better.
I don't believe this is always the case, though. I wouldn't discount having multiple statements on an event handler. In a structured programming sense, you could put all your javascript in one file to modify it centrally, but this is really a matter of taste. Personally I prefer code that only applies to one page or one section to be seperate from the more general stuff. |
|
#6
|
|||
|
|||
|
RE: how to use two
I do not discount multiple statements in event handlers, in fact I have used them quite often. I do like to take the approach of trying to use shared files whenever possible without having to many unshared functions in the file. This can somtimes be a little difficult, but with proper planning it makes for a nice system. all in all it is my personal preference to do it this way but any way that works is fine by me...
|
|
#7
|
|||
|
|||
|
RE: how to use two
I agree with you 100%. It is easy to fall into the trap of writing code without thinking ahead. Luckily I seem to have enough experience to avoid most pitfalls.
However I often find myself rewriting pieces of code a few weeks later since I have found a more efficient way to do it. If you put more work in at the beginning, you will have less work later. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > how to use two "onLoad" |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|