+ 1
can any one help me with this code ...i want to show entered hestory data
5 Respuestas
+ 4
If you know the index of object to be accessed: userData[index]["age"]
I guess that you don't, so you need to iterate over userData array to find matching object (where userData[index]["name"]=="Raas" in your example) and use that index to access the object property you want... There are many ways to achieve this: with for/while classic loop, as well as with advanced Array object methods (some require latest javascript implementations, but are mostly supported today)...
var found = false;
var index = userData.length;
while (index--) {
if (userData[index]["name"]=="Raad") {
found = true;
break;
}
}
if (found) {
/* do what you want with userData[index] object */
alert("Raad age is "+userData[index]["age"]); // or: userData[index].age
}
else {
/* do something (or not) in case of not found */
alert("Error: name not found!");
}
+ 4
Cookies and web storage (both localStorage and sessionStorage) doesn't work in mobile application context: it's a feature available only in web browsers context ^^
+ 3
Your code is messy, and your goal is unclear ^^
Anyway:
> document.getElementById(index).style.color=user[index]["preferdcolor"];
cannot work, as you don't provide any id to any element, and you only pass a number as argument;
> localStorage("i",++index);
cannot work, and I don't know what you're expected with this line: localStorage is not a function (you probably miss the dot and the method name ^^);
> localstorage.setItem("form",document.getElementsByTagName("form")[0].outerHTML);
I cannot understand what's your goal with this line anymore: this will store the outerHTML previously changed with <ul> list dynamically builded?... into the localStorage key 'form' wich you doesn't use elsewhere???
0
i know but there is abroblem in my code ...
0
i have some problems..
1. iwant to store an array of object (json).
2. i failed in getting length to an stored array becouse of that i store an index that get begger each time.
my problem is how can i steItem/getltem of this
for example:
userData=[{"name":"Khaled","age":30,"birthday":"02/02/12"}
{"name":"Gel","age":23,"birthday":"22/12/12"}
{"name":"Raad","age":40,"birthday":"18/07/78"}]
how can i get "Raad" age for example..?