On Jan 29, 4:59 pm, karthickd...@gmail.com wrote:
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;
--
Rob