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