2 or more scriptsin 1 page?

B

bacon_sandwich

I would like to put a second script into a page already
containing a script with a line of code inside the <head>
and <body> tags themselves. I need to know the correct
syntax to separate the two (not sure what to call them..)
reference (?) lines when I put the new script in.

Any ideas?! I've seen this before, and I know it's simple
but I can't remember what to use!

Fanks

.....beercansandwidge...
 
S

Steve Easton

Depending upon what the second script does, there
are a couple of different ways.
1. Combine the scripts. If the second script defines a function,
place the function in the first script, as a script can have several
"unrelated"
functions.

2. Place the script in an external .js file and call it like this:
<script type="javascript" src="extfile.js">
</script>

3. set it as a separate second script in the body.
The browser will keep them separate.

hth
 
J

Jon Spivey

Hi,
something like this?
<script type="text/javascript">
function someThing(){
// stuff
}
function someThingElse(){
// stuff
}
</script>
<body onload="someThing(); someThingElse();">
 
A

Andrew Murray

just make sure each script has <script> and </script> tags, otherwise a blank
line is all you need (if this is what you're asking).

Also make sure each script doesn't have any variable names as another script.eg a
variable integer called "A" in one script will conflict if in another script
there is also a variable called "A"....this is a simplified explanation but is
probably more relevant if two scripts that might for example have similar
functions and by coincidence have variable names the same.

as well as variable names, make sure the function names are all different. if you
have two functions in two different scripts called for example get_local_time();
then of course a conflict is going to come up when you're calling the function -
it won't know which one, or else the browser will generate an error "duplicate
identifier" or such .



other than that I suppose you can have as many as you like.
 
Top