views:

235

answers:

2

Hi,

I've the code below written in JavaScript to add a new option to the select list from the opener window:

function updateSelectList()
{
    var field = opener.document.objectdata.ticketPersonId;
    if (true && opener && field)
    {
        var val = document.createElement('option');
        var title = document.objectdata.titleId.options[document.objectdata.titleId.selectedIndex].text;
        val.text =  title + ' ' + document.objectdata.firstName.value + ' ' + document.objectdata.lastName.value + ':' + document.objectdata.username.value;    
        val.value = null;

        val.selected = true;
        field.add(val, null);
    }
}

works all fine in Firefox, Google Chrome etc but not IE 6 :-( please advise how I can make this work in IE 6 aswell.

+1  A: 

Here's my snippet:

if (oldopt!=null || !horus.brokenDOM)
  select.add(newopt, oldopt);
else
  newopt=options[options.length]=new Option(newopt.text, newopt.value, false, false);

The definition of horus.brokenDOM is left to the reader :)

IIRC, I had some difficulty with using pre-defined Option objects (generally pulled out of another selectbox) in this context with IE, hence the in-place object creation.

Pete Jordan
A: 

function updateSelectList() { var field = opener.<%= updatelist %>; if (<%= called %> && opener && field) { var val = opener.document.createElement('option'); var title = document.objectdata.titleId.options[document.objectdata.titleId.selectedIndex].text; val.text = title + ' ' + document.objectdata.firstName.value + ' ' + document.objectdata.lastName.value + ':' + document.objectdata.username.value;
val.value = <%= thePerson != null ? thePerson.getId() : null %>; val.selected = true; try { field.add(val, null); } catch(error) { field.add(val, 0); } } }

this seams to work. What a mission!