[jQuery] Re: looping through json

2009-03-27 Thread iceangel89
oh, i understand now, thanks for explaining mkmanning On Mar 27, 12:01 pm, mkmanning wrote: > Sorry, that should have read "can't": > which is basically my example. You CAN'T have elements in an array > like > this: > [  "department": {"ID": 1, "Name": "Physics"} ] > > On Mar 26, 8:59 pm, mkma

[jQuery] Re: looping through json

2009-03-26 Thread mkmanning
Sorry, that should have read "can't": which is basically my example. You CAN'T have elements in an array like this: [ "department": {"ID": 1, "Name": "Physics"} ] On Mar 26, 8:59 pm, mkmanning wrote: > This: > var departments = new Array(); > var department = {}; > department.ID = 1; > departme

[jQuery] Re: looping through json

2009-03-26 Thread mkmanning
This: var departments = new Array(); var department = {}; department.ID = 1; department.Name = "Physics"; deparments.push(department); is not a non-shorthand version of this: { "departments": [ "department": {"ID": 1, "Name": "Physics"}, "department": {"ID": 2, "Name": "Chemistry"}, "dep

[jQuery] Re: looping through json

2009-03-26 Thread iceangel89
i am using PHP. intending to use Zend Framework - still PHP On Mar 27, 11:38 am, MorningZ wrote: > Talking about my first post? > > I'm not so sure the JSON you posted > > { "departments": { >    "department": {"ID": 1, "Name": "Physics"}, >    "department": {"ID": 2, "Name": "Chemistry"}, >    

[jQuery] Re: looping through json

2009-03-26 Thread MorningZ
Talking about my first post? I'm not so sure the JSON you posted { "departments": { "department": {"ID": 1, "Name": "Physics"}, "department": {"ID": 2, "Name": "Chemistry"}, "department": {"ID": 3, "Name": "Biology"} }} is valid, as Steven points out, the last "department" wins e

[jQuery] Re: looping through json

2009-03-26 Thread mkmanning
You can't put 'bare' key/value pairs in an array, and reusing a key like department isn't really good either. A simpler structure would just be: [ {"ID": 1, "Name": "Physics"}, {"ID": 2, "Name": "Chemistry"}, {"ID": 3, "Name": "Biology"} ] Unless you have some compelling reason to assign the arr

[jQuery] Re: looping through json

2009-03-26 Thread iceangel89
ok so it works. so for my understanding, the parameters department refers to the index (0, 1, 2) and dictionary refers to the json object that i can use something like dictionary.ID on On Mar 27, 10:04 am, MorningZ wrote: > Actually.. looking @ that JSON again after Steven's post, the JSON > sh

[jQuery] Re: looping through json

2009-03-26 Thread MorningZ
Actually.. looking @ that JSON again after Steven's post, the JSON should be { "departments": [ "department": {"ID": 1, "Name": "Physics"}, "department": {"ID": 2, "Name": "Chemistry"}, "department": {"ID": 3, "Name": "Biology"} ] } Pretty sure anyways... it's been a long day :-) O

[jQuery] Re: looping through json

2009-03-26 Thread Steven Yang
I think the problem is you have the "department" 3 times in the same hash object,so the last one overrides everything. you should change "departments" to an array and loop through it > > > > > { "departments": { > >"department": {"ID": 1, "Name": "Physics"}, > >"department": {"ID": 2, "Nam

[jQuery] Re: looping through json

2009-03-26 Thread MorningZ
$.each(json.departments, function(department, dictionary) { alert("ID: " + dictionary.ID + "\nName: " + dictionary.Name); }); iceangel89 wrote: > how can i loop through json like: > > { "departments": { >"department": {"ID": 1, "Name": "Physics"}, >"department": {"ID": 2, "Name":

[jQuery] Re: looping through json and adding dom elements (options)

2009-03-25 Thread mkmanning
"remove all options from a drop down and populate it with new items from the json" "if possible, it will be good if i can have a default "null" option eg "Please select an option" that does not do anything if the user selects it or shows at the start and disappears once user selects it?" ??? If

[jQuery] Re: looping through json and adding dom elements (options)

2009-03-25 Thread iceangel89
thanks all. but what about the default "Please select a value" option? how can i have it such that the user either - cannot select that option - shown only on 1st run - can select the option but will cause the 2nd dropdown to empty - dunno if this is good idea or any other suggestions ? btw, as

[jQuery] Re: looping through json and adding dom elements (options)

2009-03-25 Thread mkmanning
I've not tried Eric's plugin, but if converting the JSON is an issue, you can use what you have (but be sure and quote the string values; preferably the keys too even though most people don't): [ {Value: 1, Item: 'Physics'}, {Value: 2, Item: 'Chemistry'}, {Value: 3, Item: 'Biology'} ]; Here's the

[jQuery] Re: looping through json and adding dom elements (options)

2009-03-25 Thread Eric Garside
Ice, I just recently released a plugin that might suit your needs. It's basically a way to transmit HTML as JSON for this exact kind of thing. Check out: code.google.com/p/hsjn Taking the case you gave, if you change the JSON your returning to: [['option', {value: 1}, 'Physics'],['option', {val