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 JS to populate the list: success:function(data){ $('#idOfYourDropdown').empty().append($.map(function(o,i){ return '<option value="'+o.Value+'">'+o.Item+'</option>'; }).join('')); } On Mar 25, 12:20 pm, Eric Garside <gars...@gmail.com> wrote: > 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', {value: 2}, 'Chemistry'], > ['option', {value: 3}, 'Biology']] > > You can do the following in your ajax success function: > > success: function(data){ > var el = $('#idOfYourDropdown').children().remove(); > $.each(data, function(){ > el.hsjn(this); > }); > > } > iceangel89 wrote: > > i am new to jquery and what i intend to do now is to load json from > > server and then based on the json, remove all options from a drop down > > and populate it with new items from the json. something like a > > cascading drop down. > > > i dunno if the json outputted is correct? do i need something like > > "department": ['xxx', 'yyy', 'zzz'] > > > [ > > {Value: 1, Item: Physics}, > > {Value: 2, Item: Chemistry}, > > {Value: 3, Item: Biology} > > ] > > > then i want to remove all <option> from a drop down then populate it > > with something like > > > <option value="1">Physics</option> > > <option value="2">Chemistry</option> > > <option value="3">Biology</option> > > > 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? > > whats the best way of having this default value? i think its very > > common.