[Javascript] Controling a SELECT from a child window

Allard Schripsema allard-schripsema at procergs.rs.gov.br
Wed Sep 21 07:01:38 CDT 2005


Hi there,
i tried to solve this yesterday, but got the same strange error

Today i found a solution though: (works in IE 6)

<script>
var oTest=window.opener.form1.cboTest.options

oTest.length = 0
oTest.length++;
oTest[oTest.length-1].text ="OK"
oTest[oTest.length-1].value ="OK"
oTest.length++;
oTest[oTest.length-1].text ="OK2"
oTest[oTest.length-1].value ="OK2"
</SCRIPT>


It seems that you are allowed to manipulate objects in other documents (as i
would expect), but when trying to insert the Option object there is
something blocking it.
I think this might be a bug, as it´s not logical behaviour as far as i can
see.

hope this helps,
allard Schripsema
www.visualDigital.com.br



-----Original Message-----
From: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu]On Behalf Of Nick Fitzsimons
Sent: Wednesday, September 21, 2005 4:52 AM
To: [JavaScript List]
Subject: RE: [Javascript] Controling a SELECT from a child window


> Actually - everything works now except ADDING an option to the select
> box (on the parent page)...the following fails:

<SNIP />

>
> Perhaps you cannot add an item to a select box on a parent window?
>

As you surmise, it's probably something to do with the fact that you're
creating the option element in one window and trying to add it to the
document in another - this is not allowed under the DOM standard.

Try:

var newOptionText = window.opener.document.createTextNode("Your text");
var newOption = window.opener.document.createElement("option");
newOption.appendChild(newOptionText);
newOption.setAttribute("value", Your value");
window.opener.document.form1.mylist.appendChild(newOption);

which uses the opener window's document to create the text node, and
should therefore be OK. It's also going to work cross-browser (IE, Mozilla
Firefox, Opera and any other browser that supports the DOM), whereas I
think I'm correct in saying that new Option() is a non-standard
Internet-Explorer-only technique.

(BTW, I haven't tested the above code, but barring typing mistakes, it
should work :-)

HTH,

Nick.
--
Nick Fitzsimons
http://www.nickfitz.co.uk/

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list