Categories
Internet Explorer JavaScript

Object doesn’t support property or method. Adding options in a <select> from a child window on Internet Explorer

Full error message:  Object doesn’t support property or method. I got this error message in Internet Explorer 7 every time i tried to run code similar to the next snippet:

window.opener.form.select[select.length]  = new Option(text, value);

The problem is that on Internet Explorer due to some mysterious security restrictions you are not allowed to add new options in a select element that resides in the parent (opener) window. In order to do this you need a workaround.

The easiest workaround is to write a function in the parent window that adds elements in the select element. The function should look something like this:

function addOptionToSelect(formName, selectName, optionText, optionValue) {
var elem = document.forms[formName].elements[selectName];
elem.options[elem.length] = new Option(optionText, optionValue);
}

This function has to be written in the parent window’s javascript and it will be accessed from child window with some code like this:

window.opener.addOptionToSelect(formName, selectName, optionText, optioValue);

Conclusion: Internet Explorer sucks.

4 replies on “Object doesn’t support property or method. Adding options in a <select> from a child window on Internet Explorer”

Is there any other work around known? The given workaround is not suitable for me. Any help will be appreciated.

Thx

Comments are closed.