PDA

View Full Version : normal fix for multiple scripts one page won't work


sticks
10-12-2002, 02:25 AM
Hi,
we are trying to get two java scripts to work on the same page, have read the Dynamic drive article on addressing this and have this in the body tag.
<body onload="init();function()" bgcolor="#FFFFFF">
However the navigation bar script is not working.

navcond .js
example http://www.familytravel.co.nz/index.html - navigation bar working - has onload of init()

alttxt.js
example http://www.familytravel.co.nz/about.html - mouseover script which has onload of function() mentioned in body tag above. This page also includes the navigation bar script but it doesn't work.

These two scripts are quite long when put together. Would you like us to paste the page here or is it easier to look online?

Thanking you.

adios
10-12-2002, 02:42 AM
Your welcome, kiwi. First:

You've got two syntax errors. Fix this -

dhtmlMenu.addItem(new NavBarMenuItem("E-Mail", "mailto:admin@<a href="http://www.enzaway.co.nz">Enzaway </a>.co.nz"));

If you're using quote characters ("literals" - as in: take me literally) within quote delimiters (as in "this is where the JS string begins - and ends") you need to use different types of quotes so the interpreter knows which is which. Alternately, you can 'escape' the same ones (\\')...in this instance

dhtmlMenu.addItem(new NavBarMenuItem("E-Mail", "mailto:admin@<a href='http://www.enzaway.co.nz'>Enzaway </a>.co.nz"));

...is fine. This:

<body onload="init();function()" bgcolor="#FFFFFF">

...is incorrect; functions are called by name, and that's not a good name for a function (you may be misunderstanding function literals). The other Mike Hall script loads immediately (without waiting for onload to run) so, just go

<body onload="init();" bgcolor="#FFFFFF">

Might work....

adios
10-12-2002, 03:03 AM
OK, oops, there's more (scripts galore):

In alttxt.js, change this:

window.onload=function(){
navtxt=(NS4)? document.layers['navtxt']........

...to this:

function init2(){
navtxt=(NS4)? document.layers['navtxt'].........

...and then:

<body onload="init1();init2()" bgcolor="#FFFFFF">

Rename the init() function that's already in the main page 'init1()'.
And:

<div id="navtxt" class="navtext" style="position:absolute; top:-100px; left:0px; visibility:hidden;z-index:99;">

...if you want the 'alttext' box to appear over the menubar.

For some reason, the menubar appears to be misbehaving in NS4 (what a shock); the submenus aren't remaining visible onmouseover. Post back if this is a problem.

sticks
10-12-2002, 03:36 AM
Thankyou Senior Member - Adios, that was so prompt, and easy to follow, and it worked!!!!
I've spent hours and hours trying to fix this so thank you, thank you, thank you.

I don't have Netscape4 to view the site in so will download and come back for help if needed. Do you think it is worth worrying about as I thought Netscape 6 was the more popular version now.

Sheryll.

adios
10-12-2002, 03:38 AM
And the hits just keep on coming...:rolleyes:

OK...more updates...

Remove this:

if(isMinNS4)document.captureEvents(Event.MOUSEMOVE);document.onmousemove=navBarGetMousePosition;

...from navcond.js, and change this:

if(NS4)document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=moveobj;

...to this:

if(NS4)document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=function(e) {
navBarGetMousePosition(e);
moveobj(e);
}

...in alttext.js. Eesh! think that's it...

sticks
10-12-2002, 04:24 AM
Hi Adios. Have made changes and can still see both scripts in IE. Let's hope those poor misinformed Netscape users can see it too :))

Thanks again, Sheryll.
ps - we have you bookmarked :))