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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:00:28+00:00 2026-05-12T09:00:28+00:00

I have made a Web page using jquery and php where all files are

  • 0

I have made a Web page using jquery and php where all files are used in a modular style. Now I have two JavaScript files which must communicate with each other. One Script generates a variable (id_menu_bar) which contains a number. I want that this variable gets transported to the second JavaScript and is used there.

How do I make that?

Here the Script

menu_bar.js

$(document).ready(function() {

function wrapper_action(id_menu_bar) {
  $(".wrapper").animate({height: "0px"});
  $("#changer p").click(function() {
    $(".wrapper").animate({height: "300px"});
  });
}

  $("#select_place li").live("click", function() {
  var wrapper_id = $(".wrapper").attr("id");
  var id_place = this.id;

  if (wrapper_id != "place")
    {
    $("#select_level li").remove();
      $("#select_building").load("menu_bar/menu_bar_building.php?placeitem="+id_place, function() {
        $("#select_building li").click(function() {
        var id_building = this.id;

          if (wrapper_id != "building")
            {
            $("#select_level").load("menu_bar/menu_bar_level.php?buildingitem="+id_building, function() {
              $("#select_level li").click(function() {
                var id_level = this.id;
                wrapper_action(id_level);
              });
            });

            }
          else if (wrapper_id == "building")
            {wrapper_action(id_building);}
        });
      });

      }
   else if (wrapper_id == "place")
    {wrapper_action(id_place);}
   });

}); 
  • 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-12T09:00:28+00:00Added an answer on May 12, 2026 at 9:00 am

    if the variable id_menu_bar is in global scope then it can be used by another script on the page.

    jQuery’s $.data() is also good for storing data against elements and means that you do not need to use a global variable and pollute the global namespace.

    EDIT:

    In response to your comment, there is a difference in how you declare variables that determines how they are scoped in JavaScript.

    Global Variables

    Outside of a function declaring a variable like

    var myVariable;
    

    or

    myVariable;
    

    will make no difference – both variables will have global scope. In fact, the second approach will give a variable global scope, even inside of a function. For example

    function firstFunction() {
        // Local scope i.e. scoped to firstFunction
        var localVariable; 
    
        // Global scope i.e. available to all other JavaScript code running
        // in the page
        globalVariable = "I'm not really hiding";
    }
    
    function secondFunction() {
        // I can access globalVariable here but only after
        // firstFunction has been executed
        alert(globalVariable); // alerts I'm not really hiding
    }
    

    The difference in this scenario is that the alert will fail and not show the value for globalVariable upon execution of secondFunction() until firstFunction() has been executed, since this is where the variable is declared. Had the variable been declared outside of any function, the alert would have succeeded and shown the value of globalVariable

    Using jQuery.data()

    Using this command, you can store data in a cache object for an element. I would recommend looking at the source to see how this achieved, but it is pretty neat. Consider

      function firstFunction() {
          $.data(document,"myVariable","I'm not really hiding"); 
          globalVariable = "I'm not hiding";
      }
    
      function secondFunction() {
          // alerts "I'm not really hiding" but only if firstFunction is executed before
          // secondFunction
          alert($.data(document, "myVariable"));
    
          // alerts "I'm not hiding" but only if firstFunction is executed before
          // secondFunction
          alert(globalVariable);
      }
    

    in this scenario, a string value "I'm not really hiding" is stored against the document object using the key string myVariable in firstFunction. This value can then be retrieved from the cache object anywhere else in the script. Attempting to read a value from the cache object without having first set it will yield undefined.

    Take a look at this Working Demo for more details.

    For reasons not to use Global Variables, check out this article.

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

Sidebar

Ask A Question

Stats

  • Questions 188k
  • Answers 188k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This problem illuded me for hours, so I'll post this… May 12, 2026 at 5:33 pm
  • Editorial Team
    Editorial Team added an answer Try this: $("#watch").html('<%= @preview_start_date %>'); And also indicate to jQuery… May 12, 2026 at 5:33 pm
  • Editorial Team
    Editorial Team added an answer This is a bug, and has been fixed in the… May 12, 2026 at 5:33 pm

Related Questions

I've had a lot of good experiences learning about web development on w3schools.com .
I have a PHP page that needs to make a call to a external
To teach myself Javascript, I'm trying to make a web page that gives users
This is my second question about this topic, the original question can be found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.