Forum Moderators: open

Message Too Old, No Replies

Working with multiple Javascripts

3 Javascripts on one page

         

xtiaan

9:06 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



Working with multiple Javascripts

Hello all... sorry if this question is very entry level... or if it has been answered on this forum before.

I would like to execute about 3 different Javascripts on one page. One controls a png pop-up, the second displays several world city times (these two work fine together)... but when I add a third to display a running world population counter, the world times disappear all together. Is there a simple answer to this problem?

Here is the code of all three java scripts as I have them in the code... this first two work fine... but the 'WorldTimes' stop working when the last JS is plugged in...? Any help would be much appreciated.

<script language="JavaScript" type="text/javascript" src="wz_tooltip.js"></script>
<style TYPE="text/css">
body { font-family:sans-serif; font-size:11px; background-color:white; }
a:link { text-decoration:none; }
.city { text-align: center; position:absolute; z-index:20; color: D3F7FF;font-weight:bold; }
.city-shadow { text-align: center; position:absolute; z-index:10; color: black;font-weight:bold; }
</style>
<script language="JavaScript" type="text/javascript" src="WorldTimes.js"></script>

<script language="JavaScript" type="text/javascript" src="worldPop.js"></script>
<div id="worldpop" class="liveTime" style="position:absolute; left:1253px; top:928px; width: 158px; height: 18px;">
<div align="center"></div>
</div>

johnl

10:41 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



hello xtiaan, and welcome.

without seeing the sources of your js-files there are many things which could go wrong. First which comes to my mind is that names of functions or variables are duplicate. Perhaps you should try to get the error-message via javascript-console or venkman in mozilla - I don't know how to do this in ie.
Good luck!

Robin_reala

11:10 pm on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Alternatively your scripts are setting window.onload directly rather than adding an event to it. But yes, seeing code would help.

xtiaan

11:16 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



Thank you both... I really don't know what im doing, so if you could please explain in 'small words'... Here are the two JS files that seem to be causing the problem...

[worldpixelproject.com...]
[worldpixelproject.com...]

Thank you...

Bernard Marx

12:38 am on Mar 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is a namespace conflict between a global variable, and a global function.
They both have the name,
now

Change the name of one or other.

xtiaan

2:28 am on Mar 17, 2006 (gmt 0)

10+ Year Member



Thank you for your input... I can see the 'now' variable in the worldPop.js - but not anywhere in the WorldTimes.js? Could you tell me exactly what i need to change... really appreciate your help...

Bernard Marx

8:49 am on Mar 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually.. forget what I said. . The var,now, is a local variable within the function, now.It should be OK. So it's not the problem.

function now(year,month,date,hours,minutes,seconds)
{
startdatum = new Date(year,month,date,hours,minutes,seconds)

var now = 5600000000.0
....

Bernard Marx

9:13 am on Mar 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Like Robin_reala says, it's likely to be an onload conflict. WorldPop.js contains an onload assignment:

window.onload=maind

This probably conflicts with another onload in an unseen script.