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 430459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:52:39+00:00 2026-05-12T19:52:39+00:00

I have about 2000 lines of javascript code for my application. A lot of

  • 0

I have about 2000 lines of javascript code for my application. A lot of this is user interaction / jQuery. Don’t worry, it all works fine 🙂

But it’s getting dificult to keep track of the code base. So I have split up the file into five files.

I thought that if I load all files, they all reside in memory and the can communicate with each other. but it does not look like it. Because, in file A, I have var currentPage = getURLvar('slpage'); and in file B I have if ( currentPage == 'someName').

But file B does not recognize the variable currentPage.

Also I have som general scripts in file C which file A nd B can use. But I guess that’s not possible to cal leither?

Any advice is much appreciated.

UPDATE

My javascript start s like this:

// FILE A
jQuery(document).ready(function() {

  var currentPage = getURLvar('slpage');

  if ( (currentPage == 'Aa') || (currentPage == 'Bb') ) { 
    init_AA();
  } 
  else if ( (currentPage == 'Cc') || (currentPage == 'Dd') ) {
    init_BB();    
  } else if ( (currentPage == 'Ee') || (currentPage == 'Ff') ) {
    init_CC();    
  }
  (...)

// FILE B
  function init_AA()
  { 
    (...)
  }

  function getURLvar(name)
  {
     //Gets the URL and returns the value of specified paramter.
  }
  • 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-12T19:52:40+00:00Added an answer on May 12, 2026 at 7:52 pm

    You’re right that it’s possible to access parts of a script in other files. The problem you’re having sounds like one of scoping.

    If your variable is in the global namespace (which isn’t a great idea) then you’ll be able to access it directly like you’ve tried.

    Alternatively, if you have your variable scoped inside a method, it will only be accessible too that method.

    In order to expose the variable you want, I’d sugest creating a common namespace for the code and scoping your seperated Javascript into the relevant namespace.

    Here’s some resources for more information:

    http://www.dustindiaz.com/namespace-your-javascript/

    http://snook.ca/archives/javascript/javascript_name

    UPDATE:

    Based on the code you’ve posted you could simply move the variable decleration outside the scope of the anonymouse function.

     var currentPage;
    
     jQuery(document).ready(function() {
    
     currentPage = getURLvar('slpage');
     ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data source with about 2000 lines that look like the following:
There is about 2000 lines of this, so manually would probably take more work
I have a directory with about 2000 files. How can I select a random
At my house I have about 10 computers all different processors and speeds (all
I have about 2000 subfolders in one folder, in each of these folders there
I have an .NET app and it runs fast through about 2000 records that
We have a database with a lot of information about Persons. I won't post
I have about 150 000 rows of data written to a database everyday. These
I have about 200 Excel files that are in standard Excel 2003 format. I
I have about 10million values that I need to put in some type of

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.