Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transfer data from child window back to parent window.

Status
Not open for further replies.

sknyppy

Programmer
May 14, 1999
137
0
0
US
It’s one of those mornings and I can’t seem to get the syntax correct.

The child window executes a query, loops through the result set which clears
and populates a select box in my parent window.

I thought I could clear all options and populate the select using the following syntax
in my child window but it doesn’t seem to work…

// clear the selection box of previous items.
window.opener.imForm.itemNbrSelect.options.length = 0;

// add default option message
window.opener.imForm.itemNbrSelect.options[0] = new Option("Choose an Item Nbr:","",false,false);

Thanks,
Dave
 
Have you tried:

window.opener.[red]document.[/red]imForm.itemNbrSelect.options.length = 0;


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
The issues are:
[1] As correctly pointed out, ff/nn are less forgiving if document is not referenced. So always have it referenced. That take out one aspect of cross-browser issue.
[2] The main problem stems from new Option() construction for cross-window operation. This is now an ie issue. ff/nn would accept the instruction and get thing done. It can be viewed like this. new Option() does make any reference to external (in a sense, far) window. Hence, it builds under the current window. But, it eventually gets "pasted" to another window. It fails to "export" and throws an exception. This just helps me to visualize the problem and should not be taken literally.

The resolution of cross-window operation is to use always createElement("option") and add method.

>[tt]// add default option message
>window.opener.imForm.itemNbrSelect.options[0] = new Option("Choose an Item Nbr:","",false,false);
[/tt]
It should now be scripted like this.
[tt]
// add default option message
var oelem,x;
oelem=opener.document.imForm.itemNbrSelect;
x=opener.document.createElement("option");
x.value="";
x.text="Choose an Item Nbr:";
oelem.options.add(x,oelem.length); //add to the end
//re-iterate if more options are to be added
[/tt]
I think then the construction is completely valid across windows and cross-browser.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top