Well, lets assume you're getting the JSON you described from the
following ajax call:

$.post('/path/to/json.php', {params: 'go here, if you need them'},
function(data){
    // "data" contains that JSON object you described

   // Also, I'm assuming your select box looks something like this:
   // <select id="mySelectBox"></select>
   var select = $('#mySelectBox');
   if (data.length) $.each(data, function(){
       $( '<option value="' + this.State.name + '">' + this.State.name
+ '</option>').appendTo( select );
   })

}, 'json');

On Jun 26, 6:46 am, liaogz82 <liaog...@gmail.com> wrote:
> Hi all,
>
> I have this JSON file that does the encoding from the states database.
> I want to extract it out using jquery and populate the select drop
> down box. the json file is being encoded in this way:
>
> [
> {"State":{"name":"AUSTRALIA CAPITAL TERRITORY"}},
> {"State":{"name":"NEW SOUTH WALES"}},
> {"State":{"name":"NORTHERN TERRITORY"}},
> {"State":{"name":"QUEENSLAND"}},
> {"State":{"name":"SOUTH AUSTRALIA"}},
> {"State":{"name":"TASMANIA"}},
> {"State":{"name":"VICTORIA"}},
> {"State":{"name":"Western Australia"}}
> ]
>
> not very sure how to extract out the values. Please help me. Thanks!

Reply via email to