Javascript

Query:

Can you have several javascript ‘thingies’ on the same page?

Am needing to use some little image carousel type things for adverts from DynamicDrive.com and while I can get one to work, when I put the second one on the page it doesn’t appear.

Just wondered if there was a limit?

Hugh


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

There’s no limit, but there is a strong chance of one function
clobbering another, or Prototype exposing shabby coding practices in
other bits of code.

Prototype (like the Rails project that spawned it) is extremely
“opinionated” code, and it does things a certain (self-described
“correct”) way. So if your DD script uses the control structure
“for … in” to iterate over an array, then it will die horribly if
Prototype was included in the same page[1]. It should be noted that
Prototype is correct in this case, but it still can bring you up short
if you’re trying to get something done in a mix-and-match manner.

Another thing that might be happening is one script is overriding the
init() function of another. Some scripts are written such that they
look out for this problem and work around it, but others might expect
to be the only thing running on the page. Prototype works around this
by using a well-documented set of functions to add “listeners” to the
page, rather than relying on anything stone-age like the onload event
in the body tag.

The best way to figure out what is going wrong is to use Firefox with
the Firebug[1] extension, and if you see a little red (x) in the
bottom right of your screen, click it. The error report will be terse
and technical, but it will tell you where to start pointing fingers.

Walter

  1. Prototype API Documentation | Array (Deprecated URL)
  2. http://getfirebug.com

On Nov 29, 2008, at 9:25 AM, hugh wrote:

Query:

Can you have several javascript ‘thingies’ on the same page?

Am needing to use some little image carousel type things for adverts
from DynamicDrive.com and while I can get one to work, when I put
the second one on the page it doesn’t appear.

Just wondered if there was a limit?

Hugh


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks for that, Walter, though not really understood I’m afraid! I’d be getting in very deep water with whatever Prototype is…:wink:

However, got it working. Seemed the code that they said to copy wasn’t quite right. Instead I copied the code from the source of their own page where the example worked…and that sorted it!

Yes I have firebug…quite useful.

regards
Hugh


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options