Bug in IE for some reason, with AJAX

Bug in IE for some reason, with AJAX

Hi,

For some reason, when caling this function with only  selected_id and field_num defined, we get this error (ONLY in IE ... tyical!)


Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; InfoPath.2; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET CLR 3.0.30729)
Timestamp: Wed, 10 Feb 2010 17:12:05 UTC


Message: 'optionValue' is null or not an object
Line: 452
Char: 10
Code: 0
URI: https://domain.org/static/ajax.js











The code is:

  1.  function update_existing_values(selected_id,next_selected_id,field_num) {
  2.          if (next_selected_id) {
  3.                          
  4.                  jQuery.getJSON("/v.f" , {  ajax_do: "wiki_ajax", id:  selected_id, field: field_num - 1 }, function(j){
  5.                                   
  6.                          var options = '';
  7.                          for (var i = 0; i <j.length; i++) {
  8.                               if (j[i].optionValue == next_selected_id) {
  9.                                  options += '<option selected="yes" value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
  10.                             } else {
  11.                                  options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
  12.                             }
  13.                          }
  14.                          jQuery("#article_is_in_" + field_num ).html(options);
  15. /*                         jQuery('#article_is_in_" + field_num  + " option:first').attr('selected', 'selected');*/
  16.                          jQuery('#article_is_in_" + field_num + " option:first').attr('selected', 'selected');
  17.                          if (j.length > 1) {
  18.                            jQuery('#article' + field_num ).show();   
  19.                          }
  20.                  })
  21.          }                     
  22.  }
The REALLY annoying  bit, is that it works fine in FF, and Chrome. For some reason, when no results are passed back - it gives a fatal error.

Can anyone suggest a possible fix? I'm at my wits end with this one :(

TIA!

Andy