Basically, I have a total of three different JavaScripts that need to be loaded when the user opens the page; let's call them script_a.js, script_b.js, and script_c.js
script_a.js and script_b.js each need to be loaded on every page; however, they do very different things (one displays text, the other creates buttons), and in the interest of readability and ease of editing later, I want to keep them separate.
script_c.js only needs to be loaded on one page; there will be a few variants (script_c2, script_c3, etc), but again, each of them only needs to be loaded on a single page.
The scripts are also too large and unwieldy for me to put them directly into the HTML (basically because I have to do a lot of different switches, and conditionals, and output formatting).
At present, the only way I know how to load a JavaScript is to use window.onload, so obviously I'm getting into the issue of competing onLoads.
"When I was a kid I used to pray every night for a new bike. Then I realised that The Lord doesn't work that way, so I stole one and asked him to forgive me."
I'm sorry, I need a little bit more guidance on how to use this...
Code:
<script type="text/javascript">
I get this; this is what I'm currently using for the single javascript I have implemented and working.
Code:
window.onload = function(){
So this here is saying "When the window loads, do the following:", yes?
Code:
functionOne();
functionTwo();
Here's what I don't understand - how do I call up to three different JavaScripts here?
Code:
script_a.js;
script_b.js;
script_c.js;
Is that how that would work? And within the code, how do I make sure that the right function loads when the script is called? There are multiple functions feeding into the main output function in each script - how do I get that one function to load when the script is called?
You don't call the actual *files*. You do, indeed, need to know the name of the function to be invoked *from* each file.
If each of those files is currently doing its own window.onload=xxxx, then you simply can find those lines and combine the xxxx's as Philip showed you.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
FunctionOne resides in a file called "script_a.js".
FunctionTwo resides in a file called "script_b.js".
I don't understand how I use this to say "look for FunctionOne in script_a.js".
Assumption: Based on the "<script type=...>" syntax, I'm assuming that this code goes in the HTML header. If that's incorrect, I would appreciate the clarification.
I figured out what was wrong, I accidentally used one of the JavaScript reserved words in one of my function names. But now this is working PERFECTLY, thank you so much!