![]() |
global variables using jstorage
I am trying out a javascript storage system called jstorage. It is like cookies but without the restrictions. I can insert a value and resurrect it later with:
Code:
insert_value();Code:
window.onload = function()I want to get the value of a previously stored item and use it with the value of the item displayed in the code above e.g: Code:
get_value('something') + get_value('done')...The question is not a jstorage issue (as far as I can see), but a way to use the retrieved get_values in the windows onload function. Everything I try doesn't let me use the values retrieved which become undefined or null when I try to combine them. Can anyone see what I am doing wrong? Here is the entire page: Code:
<html> |
you have whole javascript ???
|
You mean the packages? You can get them from here:
https://github.com/douglascrockford/...aster/json2.js and here: https://github.com/andris9/jStorage I haven't included my failed tries. |
since localStorage works in IE8, that is a WHOLE lot of code just to support IE7. imho, K.I.S.S.
i also see a lot of deprecated APIs in jStorage's source code, and everything comes back as a string instead of a rich type. yuck. if you are addung two numbers, you'll have to call "Number(a)+Number(b)" instead of just "a+b", that might be your issue here, but it wouldn't explain why one was undefined. the "this.name,this.value" is likely wrong: this refers to window in an onload event. you probably want something like: Code:
insert_value( theInputs[i].name, theInputs[i].value);edit: here is a an IE6 compatible storage routine that uses strong types and MUCH less code than jStorage: Code:
var store = (function() {if you want to support old non-ie browers (why), you'll need to provide your own ubiquitous setCookie and getCookie functions... |
Thanks rnd me. I am starting to think that my approach is wrong. I have to know first what storage system to use. But it all looks a bit insecure.
I'll ask about storage systems elsewhere. I think this js issue is (partly) solved by using the variables outside of the function(s). |
See my comments in your thread in the MySQL forum.
|
There is no reason any more for having global variables at all in JavaScript - except for one per shared library/framework.
|
Read the whole thread and the one in the MySQL forum, Felgall. He isn't really talking about JS global variables, at all. He just wants persistent storage of user input.
|
Just to finish off, using rnd me's example, this will work:
Code:
window.onload = function(){ |
Quote:
|
| All times are GMT +1. The time now is 05:49 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.