[Javascript] Controling a SELECT from a child window
David Stoltz
Dstoltz at SHH.ORG
Wed Sep 21 08:05:04 CDT 2005
You freakin ROCK!!! I bow down to the great NICK FITZSIMONS of the
javascript world!
Man, I tried everything - but your code worked beautifully!!!!
THANK YOU!!!
-----Original Message-----
From: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu] On Behalf Of Nick Fitzsimons
Sent: Wednesday, September 21, 2005 3: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