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

  • SEARCH
  • Home
  • 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 9121009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:45:41+00:00 2026-06-17T05:45:41+00:00

I got this HTML page. I wanna access variables from 2 javascript files that

  • 0

I got this HTML page. I wanna access variables from 2 javascript files that has common variables. I gotta get values from these variables pertaining to the respective javascript. I tried loading them using <script> but when i access the js variables, it only get the values from the last js file, in other words, the last loaded js file overwrites the variable values and only these values are available to access. I’d really appreciate help on this one.

Thanks!!!

  • 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-06-17T05:45:42+00:00Added an answer on June 17, 2026 at 5:45 am

    You need to namespace your variables or use variables with different names. What it sounds like you’re doing is the equivalent of:

    var x = 'foo';
    var x = 'bar';
    
    console.log(x);
    
        > bar
    

    Which should make sense. If you use namespaces though, things will work better for you. Consider two files, script-1.js and script-2.js:

    // script-1.js
    var s1 = {
        x:'foo'
    }
    
    // script-2.js
    var s2 = {
        x:'bar'
    }
    

    …then…

    console.log(s1.x);
    
        > foo
    
    console.log(s2.x);
    
        > bar
    

    That’s a rather trite example, of course.

    EDIT

    If you can’t change the files themselves do this – save off the values to some other name/object after loading script-1 but before loading script-2:

    <script type="text/javascript" src="script-1.js"></script>
    
    <script type="text/javascript">
        var s1 = {
            // Save off values here
            x:x,
            y:y
        }
    </script>
    
    <script type="text/javascript" src="script-2.js"></script>
    
    // Then...
    console.log(s1.x);  // will output the value from script-1.js
    console.log(x);     // will output the value from script-2.js
    

    Not pretty, but should work fine.

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

Sidebar

Related Questions

I've got an html page from where Im making this call periodically: function logon(id)
I got this example demonstrating AJAX from Stoyan Stefanovs Object Oriented JavaScript at page
Say I've got this HTML page: <html> <head> <script type=text/javascript> function echoValue(){ var e
I got this jQuery pre-loading script running on a index.html page loading about 10Mb
I got an html page like this: <div id=foo> first <div> second </div> </div>
Ive got this function as a html helper which should write a javascript function
I've got this page that let's you set some filter criteria, and you click
I've got big HTML page with divs that are considered pages and, I'm swapping
I've got this ruby script: require 'mechanize' agent = Mechanize.new page = agent.get http://www.speech.sri.com/projects/srilm/download.html
I got this page that works OK in Chrome, and it doesn't in IE9.

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.