Forum Moderators: open
For example
<HEAD>
<script language="JavaScript" type="text/javascript" src="external.js">
</script>
<BODY onLoad="javascript:GetTime();>
This works fine unitl I add another javascript to my 'external.js' sans any <script> of course and I get an error, then click OK, then my 'GetTime' script still works but my new script doesn't. (I got the new script from here btw...its an image slide show).
So I just tried to add the new script directly to the <BODY>. What happens there is the 'GetTime' ceases to work and the 'image slider' does work. UGH!
I looked through other posts but I couldn't find anything that matches my prob. Alas I am at a loss. Please be gentle in your reply's, I understand a fair amount but I'd still consider myself a beginner.
Thanks
Now to work out why they work independantly but not together:
The first thing I would look for is clashing function names or variable names.
Next I'd look for code which is dependant on other code already being executed: if one part hasn't finished yet another part may not work if it needs the results of the first part. I haven't made that very clear, I hope it makes sense.
Hmm, renaming functions and variables...ok that sounds easy enough. I haven't seen any books/tutorials/ other help sites that have mentioned that...Cool. People seem to be very helpful on this site and not slam those who are lacking in coding skills.
Without the full details, I'd guess it is indeed an onload conflict of some kind. This must account for more errors in cut'n'paste scripts than all others combined.
There are 2 two ways that your scripts could be grabbing the onload event (which could cause conflicts):
1) <body onload = "someFn( )">
In the HTML. By the way, the 'javascript:' bit should be dropped in your code.
2) window.onload = someFn
In the body of the script. No brackets.
In any combination of these, the last one read will be the only one 'surviving'. The safest option for you, I believe, is to fire onloads from the body tag, putting both function calls in the handler. It looks like you know this already. You could try swapping their order.
A half-decent script will at least avoid using global variables, and if it can't avoid them, will avoid names like a,b,c. A more likely conflict is that both script are using other event handlers.
The most likely candidate overall is Purple Martin's suggestion that one of the scripts is faulty. If they both work on their own however there is a conflict at large.
It seems we aren't allowed to post the locations of our problems here, and are asked not to post too much code. If it's allowed (!), stickymail me all the code (inc HTML), or zip it to:
<snip>
[edited by: korkus2000 at 6:40 pm (utc) on Jan. 19, 2004]
[edit reason] No emails please [/edit]