473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

parent.document problem

I have a page(pg1) which contains a select list (list1) in a
form(form1) and an iframe(frame1), in this iframe is a page(pg2) with
another select list(list2) in a form(form2) and I transfer the
contents of list2 to list 1 as follows

function transfer(){
for (var i=0; i<document.form2.list2.length; i++){
var cf=document.form2.list2;
addOption(parent.document.form1.list1, document.form2.list2[i].value,
document.form2.list2[i].value);
}
}
function addOption(selectbox,text,value ){
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}

Now this works ok BUT my problem is this stops working when I display
pg1 from inside another iframe(frameA)
The error is in parent.document.form1.list1 is null or not an object,
how do I get access to list1 in this situation

Oct 19 '06 #1
2 13764
ASM
Steven a écrit :
I have a page(pg1) which contains a select list (list1) in a
form(form1) and an iframe(frame1), in this iframe is a page(pg2) with
another select list(list2) in a form(form2) and I transfer the
contents of list2 to list 1 as follows
function tansfer(from,to) {
to.length = 0;
for(var i=0; i<from.length; i++)
{
to.options[i].value = from.options[i].value;
to.options[i].text = from.options[i].text;
}
}
If all your elements are nammed ( name="...")

<a href="#"
onclick="transfer('document.form1.list1',
'parent.frame1.document.form2.list2');
return false;">transfer</a>

If all your elements has an id :

<a href="#"
onclick="transfer('document.getElementById('list1' ),
'parent.frame1.document.getElementById('list2'));
return false;">transfer</a>

Case form1 in an iframe (frameA) and form2 in other iframe (frame1) :

- calling from iframeA (where is form1)

<a href="#"
onclick="transfer('document.form1.list1',
'parent.frame1.document.form2.list2');
return false;">transfer</a>
- calling from main page (whith both iframes)

<a href="#"
onclick="transfer('parent.frameA.document.form1.li st1',
'parent.frame1.document.form2.list2' );
return false;">transfer</a>

function transfer(){
for (var i=0; i<document.form2.list2.length; i++){
var cf=document.form2.list2;
addOption(parent.document.form1.list1, document.form2.list2[i].value,
document.form2.list2[i].value);
}
function transfer(){
var from = (typeof(parent.iframeA)!='undefined')?
parent.iframeA.document : document;
from = from.form1.list1;
var to = parent.iframe1.form2.list2;
to.length = 0; // if you don't want to add but to replace
for(var i=0; i<from.length; i++)
addOption(to, from[i].text, from[i].value);
}
}
function addOption(selectbox,text,value ){
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
or :
var optn = new Option(value, text);
selectbox[selectbox.length] = optn;
}

Now this works ok BUT my problem is this stops working when I display
pg1 from inside another iframe(frameA)
The error is in parent.document.form1.list1 is null or not an object,
of course, you forgive the iframe ... !
parent.frameA.document.form1.list1
or, if called from iframe 'frameA', you can also do :
document.form1.list1

--
ASM
Oct 19 '06 #2

Thanks ASM for your help I got it working
Steven

Oct 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Winfried Koenig | last post by:
Hi everyone, I have a main page: -------------------------------------------------- <html><head><title>Test</title> </head><body> <img id="img_a" name="img_a" src="image_1.png" alt=""><br>
2
by: Adrian MacNair | last post by:
I have a question in the child and I need to pass the answer back to the parent: var go = 0 var mywin = null; opts = 'width=300,height=300,status=yes,toolbar=no,menubar=no,location=no' mywin =...
1
by: Bill Borg | last post by:
Hello all, Simple chat app, where the site owner has a master window with all requests for chat, status of each room, etc., and child windows for each separate chat in which the owner is...
5
by: Peter | last post by:
1) I have a C# web application and what I am trying to do is create a popup window from a link on the parent window 2) the popup window will have a button and when a user clicks on the button the...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
6
by: paul | last post by:
HI! How do we send a variable from an Iframe page back to its parent? I have a script that calculates the iframe's window size but I need to know how to send that value back to its parent so I...
4
by: Phil Powell | last post by:
I thought this would work but it seems to not work neither in Netscape nor in IE: <script type="text/javascript"> <!-- // OBTAINED FROM http://www.javascripter.net/faq/settinga.htm //...
4
by: patrizio.trinchini | last post by:
Hi all, I'm new to XSLT and maybe my problem have a very trivial answer, but I need an expert that point me in the right direction. What I would obtain is to remove all the elements that have a...
7
by: maralfarshadi | last post by:
Dear All I am working on a Java based Web app - In this application, a window contains many textboxes which open the same child window. The user should choose among the option boxes provided and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.