Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
187
rated 0 times [  192] [ 5]  / answers: 1 / hits: 76224  / 14 Years ago, tue, october 5, 2010, 12:00:00

The requirement is following:

I have to get the location field from page.



var input= global.input = document.getElementById(Location);


Get the neighborhood area from the json file based on input and show on the page.



I have a json object and have to filter the data from the json object based on the key value (location)



var inputLocation=input.value;


In my javascript I am getting the error if I use dynamic the key.



I am able to get the json array if I do this data.Aspen but i have to get the data from a text field and it can be different so if I call data.inputLocation... its coming undefined



when i use data.(inputLocation.value) getting the following error :




XML filter is applied to non-XML value ({Aspen:[{ID:




{
Aspen:[
{
ID:Bellaire,
Name:Bellaire
},
{
ID:Champions Forest,
Name:Champions Forest
},
{
ID:Highland Village,
Name:Highland Village
},
{
ID:Museum District,
Name:Museum District
}
]
}

More From » json

 Answers
6

You can access the property using array-like syntax:


data[inputLocation]

If inputLocation is set to "Aspen", then it is the same as these two lines:


data["Aspen"]
data.Aspen

[#95416] Friday, October 1, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
christianu

Total Points: 481
Total Questions: 124
Total Answers: 99

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
2 Years ago
christianu questions
;