External .js value accessing Local JavaScript variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    External .js value accessing Local JavaScript variable

    Hi!

    I am dynamically generating external .js JavaScript resources to be used with a Tab control I created (using VB.NET).

    Originally, the JavaScript was written directly into the <head> of the pages that used Tab controls. Because it was generated in this way I was able to specify which tab was to be displayed as the "current" tab upon rendering the page in the browser.

    Since the JavaScript is now a fixed resource that resides on the server, I need to specify which tab is the current tab in a different manner.

    I've attempted using a hidden field, but because the hidden field doesn't exist when the JavaScript is executed (recall the JavaScript is executed in the <head> section which is executed before the hidden field...in the <body>.... is created).

    Since I could not a hidden field, I attempted adding the variable to the page (in the <head> section above my include for the external JavaScript). This obviously doesn't work....

    Does anyone have a recommendation as to where and how to declare this "current tab" variable?

    Thanks

    -Frinny
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    I am not entirely sure I follow can you post the HTML/JavaScript output you are getting? It is generally excepted that it is best to have JavaScript in the head tag, but it is not an absolute requirement.

    If the JavaScript are generating is in the form of a function you can just put a script call at the end of the page to call it. That way it will not be executed until all of the page elements are loaded.

    [HTML]
    <html>
    <head>
    <script>
    function someFunction() {
    .......
    }
    </script>
    </head>
    <body>
    Blah Blah Blah
    </body>
    <script>someFun ction();</script>
    </html>
    [/HTML]

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by pronerd
      I am not entirely sure I follow can you post the HTML/JavaScript output you are getting? It is generally excepted that it is best to have JavaScript in the head tag, but it is not an absolute requirement.

      If the JavaScript are generating is in the form of a function you can just put a script call at the end of the page to call it. That way it will not be executed until all of the page elements are loaded.

      [HTML]
      <html>
      <head>
      <script>
      function someFunction() {
      .......
      }
      </script>
      </head>
      <body>
      Blah Blah Blah
      </body>
      <script>someFun ction();</script>
      </html>
      [/HTML]
      Thanks for your help Pronerd.

      I ended up changing the JavaScript function that is responsible for initializing the Tab control when the page has finished loading in the browser. This function now accepts a variable as a parameter (originally this wasn't working because of some .NET issues that I have now resolved).

      It's working fine now :)

      Thanks again!

      -Frinny

      Comment

      Working...