IE - accessing select list from the iframe

K

karthickdevi

Hi,

I have a selection list in my form. I also have an iframe in this
document.

I am trying to access the selection list from my iframe as given
below. It works in Firefox but not in IE.

var aaa = "navigator";
var bbb = aaa.appName;
var selopt = "";
if(bbb == "Microsoft Internet Explorer")
{
selopt = parent.document.getElementById("select1"); - - - - -
here i am able to get the object
}
else
{
selopt = parent.document.getElementsByName('select1')[0];
}

IE :
var val = selopt.options[0].value; - - - - - - -here i am not getting
the value.

Please advise.

Thanks,
Dev.
 
R

RobG

Hi,

I have a selection list in my form. I also have an iframe in this
document.

I am trying to access the selection list from my iframe as given
below. It works in Firefox but not in IE.

var aaa = "navigator";
var bbb = aaa.appName;
var selopt = "";

There is no need to initialise a variable with a value if you intend
to set it to something later,

var selopt;

is fine.

if(bbb == "Microsoft Internet Explorer")
{
selopt = parent.document.getElementById("select1"); - - - - -
here i am able to get the object}else
{
selopt = parent.document.getElementsByName('select1')[0];

}IE :
var val = selopt.options[0].value; - - - - - - -here i am not getting
the value.

Please advise.

Firstly, ditch the browser detection code, it's worthless. If either
of the methods work in IE (and both should), they'll work in the rest
(but don't forget browser detection to allow for oldies like IE 4,
Navigator 4, some mobile browsers, et al).

Secondly, if the option doesn't have its value attribute set, it is
supposed to return the value of its text attribute. IE doesn't do
this, so I'll guess that you haven't set the value attribute.

Try something like:

var sel = parent.document.getElementById("select1");
var opt = selopt.options[selopt.selectedIndex];
var val = opt.value || opt.text;
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top