Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pre-Loading .js Files 2

Status
Not open for further replies.

JavaStripped

Programmer
Dec 18, 2002
84
0
0
CA
How do I pre-load an entire .js file before scripts start executing? I'm adrift in "Object expected" errors in code that worked fine yesterday, and I haven't changed anything except to add additional functions to the file. And yes, it's the code that worked that's giving me the trouble, or so the debugger says, but I can't find anything wrong with the added code either.

Please, somebody say this is possible somehow...

Thanks for whatever help you can provide.
 
On a related note:

Does anybody know why MSIE is reporting errors in my JavaScript comments? Yes, I'm sure they're properly opened and closed and not nested. This is happening in the same circumstances as the above errors.

Equally mysterious is MSIE's reporting of errors in the related HTML (which otherwise works fine).

Also: When I remove the new functions completely, everything else works fine and the error messages go away in both the JScript and the HTML. I'll triple-check the syntax of the new stuff and get back to this later.

BTW: Talking to oneself is therapeutic, esp. for coders. JavaStripped
"I did *not* escape. They gave me a day pass."
 
When the .js file is ready to run it's cached.

It sounds like your reffering to page elements before the browser knows they exist. What do the new function that you added do?
 
I think you're right on that... let's change my question to "Is there any way to make sure that the entire page is loaded before JS execution begins?"

The new functions (2 of them) check the values of
Code:
input type = text
elements against the
Code:
enabled
status of buttons, to see if the value of the text field (which shows a number of points available for allocation) warrants the enabling of the button (which allows the allocation of the points; the scripting of the button actions is still mostly algorithm and pseudocode comments at this point). I've narrowed the source of the errors down to one of the 2 functions, and I'll keep working on it.

That's the real purpose of comments, as I see it: To comment out questionable code in order to locate errors. As for documentation: If the code was hard to write, it should be hard to understand. JavaStripped
"I did *not* escape. They gave me a day pass."
 
onload = function() {
somefunction()
otherfunction()
}
 
Add an onload attribute to the <body> tag to call you js code

e.g.

<html><body onload=&quot;init();&quot;>
html stuff...
</body></html>
<script language=&quot;JavaScript&quot;>
function init()
{
// your initialisation stuff here
}
</script>
 
Thanks to both Guyon and gph1 for the help! I'll make a note of both procedures. JavaStripped
&quot;I did *not* escape. They gave me a day pass.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top