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="transf er('document.fo rm1.list1',
'parent.frame1. document.form2. list2');
return false;">transfe r</a>
If all your elements has an id :
<a href="#"
onclick="transf er('document.ge tElementById('l ist1'),
'parent.frame1. document.getEle mentById('list2 '));
return false;">transfe r</a>
Case form1 in an iframe (frameA) and form2 in other iframe (frame1) :
- calling from iframeA (where is form1)
<a href="#"
onclick="transf er('document.fo rm1.list1',
'parent.frame1. document.form2. list2');
return false;">transfe r</a>
- calling from main page (whith both iframes)
<a href="#"
onclick="transf er('parent.fram eA.document.for m1.list1',
'parent.frame1. document.form2. list2' );
return false;">transfe r</a>
function transfer(){
for (var i=0; i<document.form 2.list2.length; i++){
var cf=document.for m2.list2;
addOption(paren t.document.form 1.list1, document.form2. list2[i].value,
document.form2. list2[i].value);
}
function transfer(){
var from = (typeof(parent. iframeA)!='unde fined')?
parent.iframeA. document : document;
from = from.form1.list 1;
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(selec tbox,text,value ){
var optn = document.create Element("OPTION ");
optn.text = text;
optn.value = value;
selectbox.optio ns.add(optn);
or :
var optn = new Option(value, text);
selectbox[selectbox.lengt h] = 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.d ocument.form1.l ist1
or, if called from iframe 'frameA', you can also do :
document.form1. list1
--
ASM