Hello, I'm experiencing problems with the function below, called in the $ (document).ready handler under IE6.
Here is the context: #CtxForm contains 2 select boxes, one called #PlantCtx and one called #PlantID. When #PlantCtx is changed, it populates #PlantID with the related options, with the following function: function myChangeCtx() { var i = $('#PlantCtx').fieldValue(); var Plants = $('#PlantID'); $('#PlantID > option').remove(); $.each(plants[i].plants, function(id) { Plants.append($.create('option', { 'value': this.toString() }, [ this.toString() ])); }); } my $(document).ready calls the function pasted below, called mySetDefaults, which will set the default value for some form fields, using what I have in the 'request' variable, which is a javascript object that contains the GET parameters. This function will find all select elements in the #CtxForm div, which are respectively PlantCtx and PlantID, then look if there is an attribute by that name in the 'request' object, select it, and then call the 'onchange' handler for this element, so in short it does: - Populate PlantCtx - call mySetDefaults, which will first select the right option in #PlantCtx - Call $('#PlantCtx').trigger('change'), which will call myChangeCtx() - myChangeCtx() will populate PlantID with the related plantids for the newly selected plantctx - step to the next select element, which is PlantID, and select the right PlantID This works fine under IE7/FF, but with IE6 it throws an 'Could not set the selected property. Unspecified error' when calling the .attr('selected', true) for the right option in _PlantID_. Here is what I noticed: - If I call s.children("[EMAIL PROTECTED]""+request[name]+"\"]").size(), it returns 1 - If I put some alert('foo') right before calling s.children("[EMAIL PROTECTED]""+request[name]+"\"]").attr("selected", true);, it will work and wont throw any error It's really looks like jquery can see the element but it does not yet exist for IE6, as if the call to mychangeCtx() would populate the DOM but does not have the time to 'apply' it, that's really bad english and sounds strange but I can't explain what's happening. Would anyone have some thoughts about this? The function where the error is thrown is pasted below. Thanks! Regards, Renaud function mySetDefaults() { $('#CtxForm select').each(function() { var s = $(this); var name = s.attr('name').substr(s.attr('name').length-2, s.attr('name').length) == '[]'? s.attr('name').substr(0, s.attr('name').length-2): s.attr('name'); // Remove the ending [] of the name in case it's an array if (request[name]) { if (isArray(request[name])) { request[name].forEach(function(element, index, array) { s.selectOptions(element); }); } else { s.children("option:selected").removeAttr("selected"); s.children("[EMAIL PROTECTED] \""+request[name]+"\"]").attr("selected", true); } s.trigger("change"); // If there is an onchange handler registered, trigger it } }); if (request['datetime_0']) $ ('#datetime_0').val(request['datetime_0']); if (request['datetime_1']) $ ('#datetime_1').val(request['datetime_1']); }