Forum Moderators: open
My problem is the following. I'd like to write from frame1 to the option of the form of frame2 like this:
parent.frame2.document.myform.myselect.options[0] = new Option("blabla","something.htm")
It works fine in FF and IE but fails in Opera without any error message.
Any idea?
Many thanks in advance.
First off ... before worrying about getting it to work across frames, have you made sure that you can get it to work in Opera within the page?
document.myform.myselect.options[0] = new Option("blabla","something.htm")
but
parent.frame2.document.myform.myselect.options[0] = new Option("blabla","something.htm")
doesn't work at all.
1) We don't know how you have identified the frame in question id? name? both?
Try calling a global method in the frame:
parent.frame2.alert("hello");
2) Use the add method
There is an add method that is a member of the select element, and its options collection.
Try either of these:
// Assuming frame & doc referencing is OK
var select = parent.frame2.document.myform.myselect;
select.add(new Option("blabla","something.htm");
//or//
select.options.add(new Option("blabla","something.htm"));
3) Use DOM1 methods
Try document,create element etc (tiresome)
4) Frame is a different "host"
When you create an option with the Option constructor, you are doing it using the main window's JS object model, but placing it into the frame, which has it's own object model. You may need to call the constructor in the frame itself, since they are separate objects.
Option!= parent.frame2.Option
parent.frame2.document.myform.myselect.add(
new parent.frame2.Option("blabla","something.htm")
);
First of all many thanks for your reply.
Here you can find a fragment of my script:
name of the frame2 is "megye"
function kiir(ertek,x) {
var temp = parent.megye.document;
var adat = new Array('#*$!','yyyy','zzz');
temp.menu.menu1.selectedIndex=ertek;
if (ertek==21) {temp.getElementById("lat").innerHTML=" ";temp.getElementById("hely").innerHTML="képek csak úgy";parent.main.location="kepek.htm#kepek";}
else {temp.getElementById("lat").innerHTML="Látnivalók";temp.getElementById("hely").innerHTML=adat[ertek-1]+" megyében";parent.main.location=group[ertek][x][2];}
for (m=temp.menu.menu2.options.length-1;m>-1;m--) {temp.menu.menu2.options[m]=null};
for (a=0;a<group[ertek].length;a++){
var n=0; for (b=0;b<group[ertek].length;b++) {
if(a!=b) {if (group[ertek][a][0]>group[ertek][b][0]) {n++} else {;}}
else {;}}
temp.menu.menu2.options[n]=new Option(group[ertek][a][1],group[ertek][a][2])}
}
In this fragment all references to the frame2 work fine except the last row. Have you got any idea?