Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > nested frames - how to access form values

Reply
Thread Tools

nested frames - how to access form values

 
 
lstanczyk@gmail.com
Guest
Posts: n/a
 
      01-11-2008
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?
 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      01-11-2008
On Jan 11, 8:27 pm, (E-Mail 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].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.

 
Reply With Quote
 
 
 
 
lstanczyk@gmail.com
Guest
Posts: n/a
 
      01-11-2008
On Jan 11, 11:15*am, VK <(E-Mail Removed)> wrote:
> On Jan 11, 8:27 pm, (E-Mail 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 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.
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      01-11-2008
On Jan 11, 10:24 pm, (E-Mail Removed) wrote:
> On Jan 11, 11:15 am, VK <(E-Mail Removed)> wrote:
>
>
>
> > On Jan 11, 8:27 pm, (E-Mail 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.
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      01-11-2008
On Jan 11, 10:29 pm, VK <(E-Mail Removed)> wrote:
> On Jan 11, 10:24 pm, (E-Mail Removed) wrote:
>
>
>
> > On Jan 11, 11:15 am, VK <(E-Mail Removed)> wrote:

>
> > > On Jan 11, 8:27 pm, (E-Mail 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.
 
Reply With Quote
 
lstanczyk@gmail.com
Guest
Posts: n/a
 
      01-12-2008
On Jan 11, 12:48*pm, VK <(E-Mail Removed)> wrote:
> On Jan 11, 10:29 pm, VK <(E-Mail Removed)> wrote:
>
>
>
>
>
> > On Jan 11, 10:24 pm, (E-Mail Removed) wrote:

>
> > > On Jan 11, 11:15 am, VK <(E-Mail Removed)> wrote:

>
> > > > On Jan 11, 8:27 pm, (E-Mail 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
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-12-2008
VK wrote:
> On Jan 11, 8:27 pm, (E-Mail 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].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
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Frames or not Frames... Ale HTML 17 08-05-2005 12:10 AM
How to access variables (form text box values) on same form? News Groups ASP General 1 08-11-2004 01:40 PM
Link needed to go from a non-frames page to a Frames page, and load a particular frame. How? - Newbe Philip HTML 3 06-28-2004 03:06 PM
From Frames to no frames? Powerslave2112 HTML 2 01-20-2004 10:30 PM



Advertisments