Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6661307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:15:48+00:00 2026-05-26T02:15:48+00:00

I am writing a lot of JQuery code in a page and have decided

  • 0

I am writing a lot of JQuery code in a page and have decided to move some of the functions out to a separate file. So, file #1 has nothing but function definitions:

function doSomething() { ... } 

function doSomethingElse() { ... }

In the main page, I have placed my JQuery at the end of the file – following the optimization techniques found in Zakas’ book “High Performance Javascript”.

So, at the very end of the file (but before the closing body tag) I have:

<script type="text/javascript" src="/scripts/MyFunctions.js"></script>
<script type="text/javascript">
    doSomething();
    doSomethingElse();
 ....
</script>

Note that the final Javascript scripts are loaded – and run – after the page is loaded and the DOM declared. However, I get an error every time that says ‘doSomething’ is undefined.

This works without problem if the functions are included in the main script. It is only when I pull them outside that I get this error. Now, my guess is that the first file hasn’t being fully loaded/compiled when the second one makes its calls. But it seems to me that the last script (essentially acting in the “Ready” role) should be the one compiled last. When I look at JQuery and other JS files, they start with anonymous functions rather than just launching right in to function definitions so clearly there is something else going on.

Note that I don’t think it is a problem loading/finding the file: I’ve tried various paths to ensure that the path is correct and that hasn’t fixed the issue.

Does anyone have a clue why my functions aren’t being found?

Update: If I take the file contents exactly as they are found and put it into the first script tag rather than loading it from the file, this works fine. But I have checked the script file name repeatedly and it is correct. So it is something about the process of loading it from an external file.

UPDATE: Solved. I ran it through FireBug as keegan and dskrepps suggested and it jumped right out at me. I had an ASP.NET variable that I was placing in the scripts but, of course, ASP.NET isn’t parsing the file or replacing variables. When Javascript saw these replaceable values, it was dying on a parse error that wasn’t reported. So – the file was NOT being loaded and it isn’t a Javascript function call issue at all. Instead, it was an error between the keyboard and the seat. 😉

Thanks to everyone who helped!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:15:49+00:00Added an answer on May 26, 2026 at 2:15 am

    this is likely not an issue that can be solved via DOM-Ready block, i.e:

    // Do something when the DOM is ready
    jQuery(function() {
    
    });
    

    because loading JavaScript via plain ol’ script tags guarantees execution order (assuming the defer and async attributes aren’t set), so placing files in order should be enough. in short, assuming the files are actually being loaded, placing one file after another should allow the second to use functionality in the first.

    have you checked in firebug/web inspector to make sure you aren’t getting 404s for those files?

    in your myFunctions file, are you wrapping the code in an anonymous function? doing so will keep the definitions private (unless you explicitly expose them) which would prevent you from being able to access them in another block.

    for example, if myFunctions.js looks like this:

    // Anonymous closure
    (function() {
        function doSomething() {}
        function doSomethingElse() {}
    })();
    

    you won’t be able to call those functions from the page, you’ll have to add them as properties of the window or some global namespace.

    hope that helps. cheers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some code that has a lot of substitution. There's a list<char> productions
I am writing an application in JavaScript (with JQuery). The application has a lot
Writing Classic ASP code in JScript has a lot going for it: more humane
I'm currently writing some jQuery-Stuff that works a lot with js-generated HTML. Since I'm
I'm writing a lot of JQuery code recently that seems to repeat itself and
I am writing a lot of data to a file, and while keeping my
I search the web a lot when writing code. When working in Visual Studio
I have a lot of experience writing Delphi 6 Pro apps using the Skype
I am writing a page which uses a lot of in situ editing and
I've been writing Javascript code and using extensively the jQuery library. My code is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.