nested frames - how to access form values

Discussion in 'Javascript' started by lstanczyk@gmail.com, Jan 11, 2008.

  1. Guest

    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?
     
    , Jan 11, 2008
    #1
    1. Advertising

  2. VK Guest

    On Jan 11, 8:27 pm, 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.
     
    VK, Jan 11, 2008
    #2
    1. Advertising

  3. Guest

    On Jan 11, 11:15 am, VK <> wrote:
    > On Jan 11, 8:27 pm, 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.
     
    , Jan 11, 2008
    #3
  4. VK Guest

    On Jan 11, 10:24 pm, wrote:
    > On Jan 11, 11:15 am, VK <> wrote:
    >
    >
    >
    > > On Jan 11, 8:27 pm, 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.
     
    VK, Jan 11, 2008
    #4
  5. VK Guest

    On Jan 11, 10:29 pm, VK <> wrote:
    > On Jan 11, 10:24 pm, wrote:
    >
    >
    >
    > > On Jan 11, 11:15 am, VK <> wrote:

    >
    > > > On Jan 11, 8:27 pm, 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.
     
    VK, Jan 11, 2008
    #5
  6. Guest

    On Jan 11, 12:48 pm, VK <> wrote:
    > On Jan 11, 10:29 pm, VK <> wrote:
    >
    >
    >
    >
    >
    > > On Jan 11, 10:24 pm, wrote:

    >
    > > > On Jan 11, 11:15 am, VK <> wrote:

    >
    > > > > On Jan 11, 8:27 pm, 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
     
    , Jan 12, 2008
    #6
  7. VK wrote:
    > On Jan 11, 8:27 pm, 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
     
    Thomas 'PointedEars' Lahn, Jan 12, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Powerslave2112

    From Frames to no frames?

    Powerslave2112, Jan 20, 2004, in forum: HTML
    Replies:
    2
    Views:
    594
    brucie
    Jan 20, 2004
  2. Philip
    Replies:
    3
    Views:
    973
    Karl Groves
    Jun 28, 2004
  3. Ale

    Frames or not Frames...

    Ale, Aug 3, 2005, in forum: HTML
    Replies:
    17
    Views:
    964
    Adrienne
    Aug 5, 2005
  4. Replies:
    1
    Views:
    1,001
    dorayme
    Feb 10, 2006
  5. News Groups
    Replies:
    1
    Views:
    199
    Ray at
    Aug 11, 2004
Loading...

Share This Page