parent.document problem

S

Steven

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.value,
document.form2.list2.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
 
A

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.value = from.options.value;
to.options.text = from.options.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.list1',
'parent.frame1.document.form2.list2' );
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.value,
document.form2.list2.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.text, from.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
 

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,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top