nested frames - how to access form values

L

lstanczyk

I need to access form value. Form is in an Iframe (I1). Document that
holds that iframe is in another frame (fmcmain). i need to access that
element in javascript that is located in head section of topmost
document with the frameset definition.
top.frames.fmcmain.frames.I1.document.formfield does not work.
Any ideas?
 
V

VK

I need to access form value. Form is in an Iframe (I1). Document that
holds that iframe is in another frame (fmcmain). i need to access that
element in javascript that is located in head section of topmost
document with the frameset definition.
top.frames.fmcmain.frames.I1.document.formfield does not work.
Any ideas?


document.frames['fmcmain'].document.frames['I1'].document.forms[0].formfield.value

That assuming that you have only one form in the iframe of question.
If you have to have several forms in the same document then the best
way would be to set name attribute for each form and then

document.frames['fmcmain'].document.frames['I1'].document.forms['formName'].formfield.value

It is assument that all involved documents are in the same domain:
otherwise cross-domain communication will be locked by default by the
browser security settings.
 
L

lstanczyk

I need to access form value. Form is in an Iframe (I1). Document that
holds that iframe is in another frame (fmcmain). i need to access that
element in javascript that is located in head section of topmost
document with the frameset definition.
top.frames.fmcmain.frames.I1.document.formfield does not work.
Any ideas?

document.frames['fmcmain'].document.frames['I1'].document.forms[0].formfiel­d.value

That assuming that you have only one form in the iframe of question.
If you have to have several forms in the same document then the best
way would be to set name attribute for each form and then

document.frames['fmcmain'].document.frames['I1'].document.forms['formName']­.formfield.value

It is assument that all involved documents are in the same domain:
otherwise cross-domain communication will be locked by default by the
browser security settings.

Nope - i get Access Denied error.
Besides it looks like Document object does not even have framses
collection - http://www.w3schools.com/htmldom/dom_obj_document.asp
On the other hand Window object does http://www.w3schools.com/htmldom/dom_obj_window.asp
so i tried
window.frames['fmcmain'].frames['I1'].document.forms[0].formfiel­
d.value and this does not work either.
 
V

VK

On Jan 11, 8:27 pm, (e-mail address removed) wrote:
I need to access form value. Form is in an Iframe (I1). Document that
holds that iframe is in another frame (fmcmain). i need to access that
element in javascript that is located in head section of topmost
document with the frameset definition.
top.frames.fmcmain.frames.I1.document.formfield does not work.
Any ideas?
document.frames['fmcmain'].document.frames['I1'].document.forms[0].formfiel­d.value

That assuming that you have only one form in the iframe of question.
If you have to have several forms in the same document then the best
way would be to set name attribute for each form and then
document.frames['fmcmain'].document.frames['I1'].document.forms['formName']­.formfield.value

It is assument that all involved documents are in the same domain:
otherwise cross-domain communication will be locked by default by the
browser security settings.

Nope - i get Access Denied error.
Besides it looks like Document object does not even have framses
collection -http://www.w3schools.com/htmldom/dom_obj_document.asp
On the other hand Window object doeshttp://www.w3schools.com/htmldom/dom_obj_window.asp
so i tried
window.frames['fmcmain'].frames['I1'].document.forms[0].formfiel­
d.value and this does not work either.

Oops... window.frames of course, sorry for typo

window.frames['fmcmain'].window.frames['I1'].document.forms['formName']­.formfield.value

If you are getting Access Denied error then - as I said - one of
documents is not in the same domain as others. Nothing you can do then
besides manually changing security settings of all involved browsers.
 
V

VK

On Jan 11, 8:27 pm, (e-mail address removed) wrote:
I need to access form value. Form is in an Iframe (I1). Document that
holds that iframe is in another frame (fmcmain). i need to access that
element in javascript that is located in head section of topmost
document with the frameset definition.
top.frames.fmcmain.frames.I1.document.formfield does not work.
Any ideas?
document.frames['fmcmain'].document.frames['I1'].document.forms[0].formfiel­d.value
That assuming that you have only one form in the iframe of question.
If you have to have several forms in the same document then the best
way would be to set name attribute for each form and then
document.frames['fmcmain'].document.frames['I1'].document.forms['formName']­.formfield.value
It is assument that all involved documents are in the same domain:
otherwise cross-domain communication will be locked by default by the
browser security settings.
Nope - i get Access Denied error.
Besides it looks like Document object does not even have framses
collection -http://www.w3schools.com/htmldom/dom_obj_document.asp
On the other hand Window object doeshttp://www.w3schools.com/htmldom/dom_obj_window.asp
so i tried
window.frames['fmcmain'].frames['I1'].document.forms[0].formfiel­
d.value and this does not work either.

Oops... window.frames of course, sorry for typo

window.frames['fmcmain'].window.frames['I1'].document.forms['formName']­..formfield.value

If you are getting Access Denied error then - as I said - one of
documents is not in the same domain as others. Nothing you can do then
besides manually changing security settings of all involved browsers.

I never used nested (i)frames so decided to check myself:

---------
doc0.html
---------
---------

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script>
function test() {
var v = window.frames['fmcmain'].
window.frames['I1'].
document.forms[0].formfield.value;
window.alert(v);
}
</script>
</head>

<body bgcolor="#FFFFFF" onload="
window.setTimeout('test()',1000);
">
<iframe src="doc1.html" name="fmcmain"></iframe>
</body>
</html>

---------
doc1.html
---------
---------

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<iframe src="doc2.html" name="I1"></iframe>
</body>
</html>

---------
doc2.html
---------
---------

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<form method="post" action="">
<input type="hidden" name="formfield" value="formfield value">
</form>
</body>
</html>

Having all three docs saved in the same directory, open doc0.html and
it will happily report "formfield value" as expected.

So you are having the same-domain-only access violation and nothing
you can do about it universally.

If all involved pages are at least in the same top level domain (say
sample.com) then you may relax the security by placing script block
into each involved page with instruction
document.domain = 'sample.com';

If any or all of involved pages are from completely different domains
(say sample.com and sample.net) then no one browser will ever allow
you to do that. You have to rethink your project then.
 
L

lstanczyk

On Jan 11, 10:24 pm, (e-mail address removed) wrote:
On Jan 11, 8:27 pm, (e-mail address removed) wrote:
I need to access form value. Form is in an Iframe (I1). Document that
holds that iframe is in another frame (fmcmain). i need to access that
element in javascript that is located in head section of topmost
document with the frameset definition.
top.frames.fmcmain.frames.I1.document.formfield does not work.
Any ideas?
document.frames['fmcmain'].document.frames['I1'].document.forms[0].formfiel­­d.value
That assuming that you have only one form in the iframe of question.
If you have to have several forms in the same document then the best
way would be to set name attribute for each form and then
document.frames['fmcmain'].document.frames['I1'].document.forms['formName']­­.formfield.value
It is assument that all involved documents are in the same domain:
otherwise cross-domain communication will be locked by default by the
browser security settings.
Nope - i get Access Denied error.
Besides it looks like Document object does not even have framses
collection -http://www.w3schools.com/htmldom/dom_obj_document.asp
On the other hand Window object doeshttp://www.w3schools.com/htmldom/dom_obj_window.asp
so i tried
window.frames['fmcmain'].frames['I1'].document.forms[0].formfiel­
d.value and this does not work either.
Oops... window.frames of course, sorry for typo
window.frames['fmcmain'].window.frames['I1'].document.forms['formName']­.fo­rmfield.value

If you are getting Access Denied error then - as I said - one of
documents is not in the same domain as others. Nothing you can do then
besides manually changing security settings of all involved browsers.

I never used nested (i)frames so decided to check myself:

---------
doc0.html
---------
---------

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script>
 function test() {
  var v = window.frames['fmcmain'].
  window.frames['I1'].
  document.forms[0].formfield.value;
  window.alert(v);
 }
</script>
</head>

<body bgcolor="#FFFFFF" onload="
 window.setTimeout('test()',1000);
">
<iframe src="doc1.html" name="fmcmain"></iframe>
</body>
</html>

---------
doc1.html
---------
---------

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<iframe src="doc2.html" name="I1"></iframe>
</body>
</html>

---------
doc2.html
---------
---------

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<form method="post" action="">
  <input type="hidden" name="formfield" value="formfield value">
</form>
</body>
</html>

Having all three docs saved in the same directory, open doc0.html and
it will happily report "formfield value" as expected.

So you are having the same-domain-only access violation and nothing
you can do about it universally.

If all involved pages are at least in the same top level domain (say
sample.com) then you may relax the security by placing script block
into each involved page with instruction
 document.domain = 'sample.com';

If any or all of involved pages are from completely different domains
(say sample.com and sample.net) then no one browser will ever allow
you to do that. You have to rethink your project then.- Hide quoted text -

- Show quoted text -

You are right - it is different domains problem. I am trying to have a
frameset document on let's say localhost that will prepopuilate fields
on remotely hosted server.
Thanx for your help
 
T

Thomas 'PointedEars' Lahn

VK said:
I need to access form value. Form is in an Iframe (I1). Document that
holds that iframe is in another frame (fmcmain). i need to access that
element in javascript that is located in head section of topmost
document with the frameset definition.
top.frames.fmcmain.frames.I1.document.formfield does not work.
Any ideas?

document.frames['fmcmain'].document.frames['I1'].document.forms[0].formfield.value

`frames' is a collection property of Window objects, not of Document
objects. Frame objects are Window objects:

window.frames['fmcmain'].frames['I1'].document.forms[0].formfield.value


PointedEars
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top