www.webdeveloper.com
Results 1 to 3 of 3

Thread: Variables and Scope

  1. #1
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    112

    Variables and Scope

    I have a question about the scope of variables in javascript.

    I have a couple of variables in a js file that I include in my page file:
    <script type="text/javascript" src="js/val_dg.js"></script>

    I want to move these variables out of the val_dg.js file and into page file itself so that i have something like

    HTML Code:
    <script type="text/javascript">
    var val_error = 1;
    var err_msg_val = "Required";
    var use_keyup=1;
    var returnval='';
    </script>
    <script type="text/javascript" src="js/val_dg.js"></script>
    I've tried the above and it seems to work. but I'm a little shakey on using this technique.

    What do the experts think...???




    .

  2. #2
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,755
    If those variables are only going to be used on one page, then there's nothing semantically wrong with it. If those variables are going to be used on multiple pages, I'd say put it in an external file, and if you want to change the value of those variables depending on the page, just add a SCRIPT tag that sets the values of the variables after you include the external file.

  3. #3
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    112
    thanks for the info. appreciate it...!



    .

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles