Global Variable vs Hidden Input TextBoxes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mouac01@yahoo.com

    Global Variable vs Hidden Input TextBoxes

    Currently I'm using hidden input textboxes to store session variables
    (eg. login_id, first_name, last_name). So when I need to use the
    values in a fuction I would do login_id.value, etc.. I'm thinking if
    it's better to just set the login_id, etc.. as global variables. I
    may have a lot of variables and the session may be long. I'm worried
    that I might lose global variables due to memory leaks and other
    issues. In my mind if I store it in a hidden textbox the text
    actually is stored on the page so it won't just disappear. Any
    thoughts? Thanks...
  • SAM

    #2
    Re: Global Variable vs Hidden Input TextBoxes

    mouac01@yahoo.c om a écrit :
    Currently I'm using hidden input textboxes to store session variables
    (eg. login_id, first_name, last_name). So when I need to use the
    values in a fuction I would do login_id.value, etc.. I'm thinking if
    it's better to just set the login_id, etc.. as global variables. I
    may have a lot of variables and the session may be long. I'm worried
    that I might lose global variables due to memory leaks and other
    issues. In my mind if I store it in a hidden textbox the text
    actually is stored on the page so it won't just disappear. Any
    thoughts? Thanks...
    Really, JS global variables can disappear ?

    Is there a difference between :
    - to remember what is coded in the body (hidden values) of the page
    - and to remember what is coded in the head (JS global variables)?

    Now, if you need these hidden values, yes why not to use them instead to
    work with their JS clones.


    --
    sm

    Comment

    • Randy Webb

      #3
      Re: Global Variable vs Hidden Input TextBoxes

      mouac01@yahoo.c om said the following on 2/8/2008 4:58 PM:
      Currently I'm using hidden input textboxes to store session variables
      (eg. login_id, first_name, last_name). So when I need to use the
      values in a fuction I would do login_id.value, etc.. I'm thinking if
      it's better to just set the login_id, etc.. as global variables. I
      may have a lot of variables and the session may be long. I'm worried
      that I might lose global variables due to memory leaks and other
      issues. In my mind if I store it in a hidden textbox the text
      actually is stored on the page so it won't just disappear. Any
      thoughts? Thanks...
      Namespace them.

      var myVariables = {}
      myVariables.log in_id = "something"
      myVariables.fir st_name = "First name"

      And so on. Then, you only have one chance for a name clash and you are
      only creating one global variable name.

      I think you are being overly-paranoid about memory leaks losing global
      variables though.

      --
      Randy
      Chance Favors The Prepared Mind
      comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
      Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

      Comment

      Working...