Multiple javascripts

They have: 23 posts

Joined: Jul 2000

What code, if any, do I use to place more than one Javascript on the same page?? Sad

AndyB's picture

They have: 344 posts

Joined: Aug 1999

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi quiet,

That depends on what you mean. You can put as many scripts as you want between the script tags. For example,
<script language="javascript">

</script>

The only exception to the above is if you are 'including' a js file. That needs to have its own script tag, as in:
<script language='javascript' src='someName.js'>
</script>
<script language="javascript">

</script>

If, by your question, you mean how do you resolve conflicts between two cut&paste scripts:
1) look at the variables. If they are global (declared outside of a function), you will probably find one or more them use the same name (i, messages, divLayer, etc). You will have to either rewrite the scripts so that you get rid of as many globals as possible or rename the variables.

If you mean how do you get a script to run two or more times with different data, as in a slideshow or menu system, you will need to either make copies of all the code, rename the copies, and its global variables -- or, rewrite the scripts so that they pass arguments and the 'this' keyword so that the script is no longer hardwired.

Vinny

Where the world once stood
the blades of grass cut me still

They have: 23 posts

Joined: Jul 2000

Thanks, Andy for the URL and Vinny, once again we meet and I learn.
quiet

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.