By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,295 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

input values not recognized in dinamicly loaded IFRAMEs

P: n/a
problem: input values not recognized in dinamicly loaded IFRAMEs

here is the thing I have a parent window that has an IFRAME
I then load a diffrent page into the IFRAME that contains an input

when I try to access - iFrm.document.all["grid_name"].value

i get an error saying that - "value is null or not an object"

I tryed checking to make sure the page is fully loaded using:
document.readyState=="complete"
and it is loaded and completed

the weirdest thing is that when debugging the error I can see the value
in the debbuger
and after that I get the value alerted just fine
so how come I get an error ?????

parent.html:

<script>
function loadIframe()
{
var iDiv = document.getElementById("pannel1");
alert("iDiv.id = " + iDiv.id);
var iFrm = document.getElementById("ifrm");
//ByTagName("IFRAME")[0];
alert("iFrm.id = " + iFrm.id);
iFrm.src="child.html"; //ALSO WORKS:
location.href="child.html";
}

function showGridName()
{
var iFrm = document.getElementById("ifrm");
alert("iFrm.src = " + iFrm.src);
var gridName = iFrm.document.all["grid_name"].value;
alert("gridName");
}
</script>
</head>
<body>
<input type="button" value="load frame" onclick="loadIframe();">&nbsp;
<input type="button" value="grid name" onclick="showGridName();">
<div id="pannel1" name="pannel1">
<IFRAME id="ifrm" name="ifrm" src="blank.html" grid_name="grid2">
</IFRAME>
</div>
</body>
<html>

child.html - in IFRAME

<html><body>
<form name="frm" action="blank.html">
<input type="hidden" id="grid_name" name="grid_name">
<input type="submit" value="send">
</form>
</body><html>

blank.html in IFRAME:

<html><body>blank page</body><html>

Jun 28 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
shocron wrote:
problem: input values not recognized in dinamicly loaded
IFRAMEs

here is the thing I have a parent window that has an
IFRAME I then load a diffrent page into the IFRAME that
contains an input

when I try to access - iFrm.document.all["grid_name"].value

i get an error saying that - "value is null or not an
object"

<snip>

The - document - property of IFRAME elements (if implemented at all as
it is non-standard) may or may not refer to the document contained
within the IFRAME. Often they refer to the document in which the element
is contained (which has no input element).

Generally, the most cross-browser and reliable approach to accessing the
contents of sub-frames is to use the - frames - collection of the
window/global object that contains the frame, give the IFRAME/FRAME a
name attribute and index the - frames - collection with that name. The
result of such a reference is the global/window object for the contained
frame, which will have (assuming the frame has loaded) a - document -
property that refers to the document within the frame.

Richard.
Jun 28 '06 #2

P: n/a
I have also tried -

document.frames['myFrameName'].document.all["myInput"].value

but I get the same error value is not recognized although
I can see the value in debug mode

when I try to access - iFrm.document.all["grid_name"].value

i get an error saying that - "value is null or not an
object"

<snip>

The - document - property of IFRAME elements (if implemented at all as
it is non-standard) may or may not refer to the document contained
within the IFRAME. Often they refer to the document in which the element
is contained (which has no input element).

Generally, the most cross-browser and reliable approach to accessing the
contents of sub-frames is to use the - frames - collection of the
window/global object that contains the frame, give the IFRAME/FRAME a
name attribute and index the - frames - collection with that name. The
result of such a reference is the global/window object for the contained
frame, which will have (assuming the frame has loaded) a - document -
property that refers to the document within the frame.

Richard.


Jun 29 '06 #3

P: n/a
shocron wrote:
I have also tried -

document.frames['myFrameName'].document.all["myInput"].value

but I get the same error value is not recognized although
I can see the value in debug mode
Hi,

I think you want:
parent.frames['myFrameName'].document...

Futhermore: document.all[..] is bad. It is not standard and will fail on
non-IE browsers.
Use the following way to address an element in a form:
document.forms["formname"]["elementname"].value

or in your case:

parent.frames['myFrameName'].document.forms["formname"]["elementname"].value

Or use getElementById("myElement") to get a reference to myElement.

One other thing to watch: Are you maybe using different domains for the
maindocument and the document in the IFRAME? JS is not able to script
across different domains (luckily).

Regards,
Erwin Moller


> when I try to access - iFrm.document.all["grid_name"].value
>
> i get an error saying that - "value is null or not an
> object"

<snip>

The - document - property of IFRAME elements (if implemented at all as
it is non-standard) may or may not refer to the document contained
within the IFRAME. Often they refer to the document in which the element
is contained (which has no input element).

Generally, the most cross-browser and reliable approach to accessing the
contents of sub-frames is to use the - frames - collection of the
window/global object that contains the frame, give the IFRAME/FRAME a
name attribute and index the - frames - collection with that name. The
result of such a reference is the global/window object for the contained
frame, which will have (assuming the frame has loaded) a - document -
property that refers to the document within the frame.

Richard.


Jun 29 '06 #4

P: n/a
I tried -
document.frames[0].document.forms[0]["elementname"].value

and it worked.

this is the first time I have used the syntax
document.forms["form_name"]["element_name].value

and it is the only syntax that worked
all others .all["id"].value .getElementByID()
document.formName.elementName.value
have all failed miserably

which makes you think - how come there is no reference, nowhere for
the correct, cross browser, fail safe syntax to use

thanks

Jun 29 '06 #5

P: n/a
shocron wrote:
I tried -
document.frames[0].document.forms[0]["elementname"].value

and it worked.

this is the first time I have used the syntax
document.forms["form_name"]["element_name].value

and it is the only syntax that worked
all others .all["id"].value .getElementByID()
document.formName.elementName.value
have all failed miserably

which makes you think - how come there is no reference, nowhere for
the correct, cross browser, fail safe syntax to use
What makes you think there is no reference to this?
The use of .all[] is IE only, it is described in any good book/site, and
should be avoided unless you are a M$-only guy.

You DO test your pages on Firefox before publishing them on the net, don't
you?

I would like to misuse this oppertunity to advise a great book to you:
'Dynamic HTML, the definitive reference' from O'Reilly.

No, I do not work for them. :-)

Regards,
Erwin Moller

thanks


Jun 30 '06 #6

P: n/a
still doesn't work
let me explain my situation
I have number of tabs in a web page named pannel1...pannelxx
in some of the tabs I have an IFRAME containing my pages
I want to load my IFRAME dynamicly when I click the tab

so I do:

var pannelDiv = window.document.getElementById('panelpanel'+i);
var theFrame = pannelDiv.getElementsByTagName("IFRAME")[0];

and then I load the frame using: theFrame.src = "myPage.html";

now here comes the tricky part
when I try from to access an input inside my frame

using:
var frameName=theFrame.id;

alert(document.frames[frameName].document.forms[0]["grid_name"].value);

or any of the syntaxes I have mentioned before It fails
needless to say it works fine when the Iframe is preloaded
and not loaded dynamicly

then I just use

var grid_name = eval(frameName+".getGridName()");

one syntax did work however using
frame index like frames[3].document,,,
the problem is that not all tabs have an Iframe so I dont know the
ordinal no
for the frame in advance just it's name

any ideas ???

Jul 3 '06 #7

P: n/a

shocron написав:
needless to say it works fine when the Iframe is preloaded
and not loaded dynamicly
>needless to say it works fine when the Iframe is preloaded
and not loaded dynamicly
Set timeout between loading document into iframe and accessing its
elements:

function f1()
{
....
theFrame.src="some.htm";
setTimeout("getIFrameData('"+theFrame.id+"')", 50);
...
}

function getIFrameData(frameId)
{
var doc;
if (document.all) //IE
doc = frames[frameId].document;
else //Gecko based browsers
doc = document.getElementById(frameId).contentDocument;

//here you can access iframe document data
......
}

Jul 3 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.