SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    on page refresh, how to keep variable value?

    Is there a way to keep a variable value on page refresh, if I have

    var x=0;

    but then a users does somethibng that makes that value become

    x=4;

    and then the page is refreshed, is there a way to keep that value of 4 for the x variable or it will always reset to the original value?

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have these options (in order of preference):

    1. Sessions (server side)
    2. Cookies (client side)
    3. URL Query String

  3. #3
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hurrakan View Post
    You have these options (in order of preference):

    1. Sessions (server side)
    2. Cookies (client side)
    3. URL Query String
    well, I been trying the url one but canīt seem to get it right, I am trying it like this but oviously is not working, can you help me on it?

    Code JavaScript:
    var enable_button=location.href+'?enable_button=enable_button' || 0;

    I did the || 0 because I want it to assign the value 0 to it when the page is first loaded

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should really use Sessions because the others can be manipulated by the user.

  5. #5
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hurrakan View Post
    You should really use Sessions because the others can be manipulated by the user.

    Thank you for your help, I started rerading some posts about the sessions and found a recommendation to store the value in a hidden field, and that worked fine for what I am trying to do


Bookmarks

Posting Permissions

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