little question

K

Kevin Auch

Hi,

I want to know if it's possible from a popup to add Option on a Select
object on the parent, by just calling the Select object like this :

var openerForm = window.top.opener.document.forms[0];
opt = new Option(theLabel, theValue,false,false);
openerForm.mySelect.options = opt;

Or maybe I must use another way by passing the option like a string on an
hidden field an evaluate this string ?

Thanks for your help

Kevin


//--------------------------------------------------
Kevin Auch
MVP .NET
CodeWise Community Member
http://www.dotnet-fr.org
----------------------------------------------------//
 
R

Richard Cornford

Kevin said:
I want to know if it's possible from a popup to add Option
on a Select object on the parent, by just calling the Select
object like this :

var openerForm = window.top.opener.document.forms[0];
opt = new Option(theLabel, theValue,false,false);
openerForm.mySelect.options = opt;


No it is not.
Or maybe I must use another way by passing the option like a
string on an hidden field an evaluate this string ?

It is generally the rule in javascript that anything that proposes using
the - eval - function is the worst approach available.

The problem is (ultimately) the location in which the memory that your
new Option uses resided. If you use - new Option( ... ) - the new option
element is created in the window/frame in which the - Option -
constructor being used is located. Attempting to add that option to an
element of a form in another window/frame will not work.

Usually the simplest solution is to create a function in the
frame/window in which the form resides that will take (string and/or
number) arguments and locally create a new Option and insert it in the
form, calling that function from the separate frame/window.
//--------------------------------------------------

If you are going to post to Usenet you should use the specified standard
signature separator.
Kevin Auch
MVP .NET

MVP?

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,274
Latest member
JessMcMast

Latest Threads

Top