Seems to me you're missing a double dot:

{"title": "Roman History", "ID","13"}

should be

{"title": "Roman History", "ID": "13"}

Also what's the point in using option groups without a label?
Something like this should do:

JS:
var $history = $('#history > optgroup');

$.each(json.channel.subtopics, function(i,item) {
    $history.append(new Option(this.title, this.id));
});

HTML:
<select id="history">
  <optgroup label="History">
  </optgroup>
</select>

On Nov 24, 2:09 am, claudes <[EMAIL PROTECTED]> wrote:
> i have this json feed:
> {
>     "channel": {
>         "title": "History",
>         "id": "12",
>         "subtopics": [
>                         {"title": "Roman History", "ID","13"},
>                         {"title": "Greek History", "ID", "1"},
>                         {"title": "French History", "ID", "1"}
>         ] // subtopics
>     }
>
> }
>
> and i want to populate a select box to result as follows:
>
> <option>History>
> <optgroup>
> <option value="ID">Roman History</option>
> ...
> </optgroup>
> </option>
>
> this is the code i have so far:
>
> $.getJSON("jrss.js", function(json) {
>                 var html = '<select id="select-program">';
>                         response = {
>                  values: [],
>                  count: 0
>              };
>                 $.each(json.channel.subtopics,function(i,item) {
>                         html += '<option>history</option>'; // not sure where 
> this goes
>                         response.values[i] = item.title;
>                         html += '<optgroup>';
>                         html += '<option>'+item.title;+'</option>';
>                         html += '</optgroup';
>                 });
>
>                         html += '</select>';
>
>                         $('body').append(html);
>                 });
>
> });
>
> var jJSON = {
>     getValues: function(obj,num) {
>         return jJSON[obj]["values"];
>     }
>
> }
>
> I can currently get the code to populate the <optgroup> correctly. I still
> cannot get it to assign id as the value. and i cannot dynamically assign the
> <option>history</history> dynamically...it returns undefined.
>
> can anyone help me with these two issues? thanks
> --
> View this message in 
> context:http://www.nabble.com/populate-selectbox-with-json-feed...partially-w...
> Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to