468,545 Members | 1,905 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,545 developers. It's quick & easy.

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 13465
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Winfried Koenig | last post: by
2 posts views Thread by Adrian MacNair | last post: by
1 post views Thread by Bill Borg | last post: by
5 posts views Thread by Peter | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.