Forum Moderators: open

Message Too Old, No Replies

Option problem in Opera

         

Blackfriar

9:08 pm on Feb 13, 2006 (gmt 0)

10+ Year Member



Hi for everybody!

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.

DrDoc

9:17 pm on Feb 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld! [WebmasterWorld.com]

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?

Blackfriar

9:17 am on Feb 14, 2006 (gmt 0)

10+ Year Member



As I mentioned script works fine in FF and IE.
Otherwise the following script row also works fine in a frame in Opera.

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.

kaled

12:04 pm on Feb 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Deleted

Bernard Marx

12:26 pm on Feb 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Referencing

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")
);

Blackfriar

6:08 pm on Feb 14, 2006 (gmt 0)

10+ Year Member



Dear Bernard,

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?

Bernard Marx

8:16 pm on Feb 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like it was reason (4). We have to use the constructor in the frame's own JS object model.

With this:

<frame src = "blah.htm" name="megye" id="megye">

This works for me:

var m = top.frames.megye;
m.document.menu.menu2.options.add( new m.Option("foo","bar"));

Blackfriar

5:42 am on Feb 15, 2006 (gmt 0)

10+ Year Member




Great solution. Thanks again for your kind help Bernard!