I am using the following function as a test case for my application:
$(function() {
var json = {
"people": {
"person": [{
"name": "Peter",
"age": 43,
"sex": "male"},
{
"name": "Zara",
"age": 65,
"sex": "female"}]
}
};
$.each(json.people.person, function(i, v) {
if (v.name == "Peter") {
alert(v.age);
return;
}
});
});
This simply searches a set of JSON data for a static input, which in this case is the name "Peter", and returns his 'age'. I want to modify this function to pull input from a text field and use it in place of the static string "Peter" so I can search for any name Id like. The function will be called from a submit button.
That is my first obstacle.
My second is Id like to use the subset of the result as an object, rather than a string, in my application. In other words, if I placed a name in a text field the function would find the name within the JSON data and return, in this case, 'age' as an object that I can then use for other calculations in the work flow.
Can anyone help me with this?
Thanks!