PDA

View Full Version : 2 Javascripts on one page


fou4swords
06-14-2006, 05:46 AM
hey,

I have this Javascript problem.. you see.. I have 2 on the same page.. and i hear that 2 Javascripts... when not configured properly.. can cause one or the other to not work.. here is the URL http://four4swords.buhh.net/Artifacts/four4swordsPAGE.htm In there.. Is two scripts.. but they're not co-existing.. nicely.. enough for them to both work.. so can someone tell me what i did wrong.. and what i can do to fix it?

MandyJay
06-14-2006, 06:32 AM
Can you give us lnks to where you got the two scripts from. We would need to see what they are meant to do and to check the instructions. If they are not working on your page, it is hard to know what we are meant to be seeing .... thanks

MJ

fou4swords
06-15-2006, 01:34 AM
Okk.. Well One is meant to be Rain drops and another is meant to be a trembling message .. Where i got the tremoring message is from here : http://www.dynamicdrive.com/dynamicindex10/tremble.htm

And where i got the rain drops is from here : http://www.javafile.com/imagefx/rain.php

Yup .. those are the places where i got them from!

MandyJay
06-15-2006, 02:31 AM
That was a tricky one. Okay I got them both to work in IE7 - but the raindrops don't work in Firefox anyway .... but the jiggle text does.

Brief explanation .... both scripts have a "body onload" or "window onload"... i.e. both scripts tell the browser that the moment the page/window loads it has to ...... init() .... begin. When you have more than one script giving that instruction, the last one take preference, which is why the raindrops worked but not the jiggle. Normally you just have to combine them both within the body tag. But the raindrops was coded differently, so not quite so straightforward to do. But, what I have basically done, which appears to work, is taken out the onload event for the jiggle and added it to the script of the raindrops with no onload actually in the body tag itself or head tags ....

The thing is, you must have the jiggle script that goes into the body of the document BEFORE the raindrops ..... or the jiggle won't jiggle ... hahahah.

Okay ..... look at the jiggle script in the head tags, the very last line of the script is this in bold/black - DELETE IT (don't accidentally delete the </script> though:

window.onload=init

</script>

the rest of that script stays the same including what goes into the body of the document.

Now the raindrop script MUST be inserted into the body of the document AFTER the jiggle line which is like this:

<p><span id="jiggle0" class="jc"><b>This is the jiggle script</b></span></p>

Add this line (in black/bold) to the top of the raindrop script:

<!-- Begin
init();
var no = 50;

and you should be good to go.

NOTE: do NOT copy and paste directly from this forum posting or the code could become corrupted, paste into notepad first then recopy and paste into html of your page.

MJ

fou4swords
06-15-2006, 02:42 AM
Awesome! They are jiggling!..

If i were to add in more java scripts in the future.. would i do that same thing to get them to work?

MandyJay
06-15-2006, 02:49 AM
If i were to add in more java scripts in the future.. would i do that same thing to get them to work? Not necesarily, and I would imagine some scripts could clash and no workaround ....you would just have to see what happens.

MJ