www.webdeveloper.com
Results 1 to 8 of 8

Thread: iframe - parent window communication

  1. #1
    Join Date
    May 2004
    Posts
    78

    iframe - parent window communication

    I have a page in which I include an <iframe>. When submit button is clicked I run a JavaScript that fills iframe's src: document.all.iframList.src="script.jsp?" + parameters;
    While script.jsp does it's thing I change the submit button on the page to disabled. But to change it back...that a problem. How do I know when iframe finished loading and how do I set submit button back to enabled?

    thanks,
    camokat

  2. #2
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    In your IFrame, try this...

    Code:
    <script type="text/javascript"><!--
    onload = function(){
     parent.forms["formName"].submitButtonName.disabled = false;
    }
    //--></script>
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  3. #3
    Join Date
    May 2004
    Posts
    78
    thanks Jona!
    It works, but I get a JavaScript error pointing at line where it enabled the button again:
    parent.document.forms["merge_form"].submitButton.disabled = false;

  4. #4
    Join Date
    Sep 2004
    Location
    Midwest
    Posts
    1,629
    <HTML>
    <Head>
    <Script Language=JavaScript>

    function checkState(){

    if (window.frames['dynFrame'].document.readyState == 'complete'){submitBtn.disabled = false}
    else {setTimeout("checkState()",2000)}

    }

    function swapThis(isIFrame,isSRC){

    submitBtn.disabled = true;
    isIFrame.location = isSRC;
    checkState();
    }

    </Script>
    </Head>
    <Body>
    <Div align=center>
    <IFRAME
    Name = 'dynFrame'
    SRC= ''
    WIDTH='700'
    HEIGHT='250'
    Frameborder='yes'
    Scrolling='auto'>
    </IFRAME>
    </Div>
    <br>
    <input type=button value="Submit" id='submitBtn' onClick="swapThis(dynFrame,'newSrc.html')">
    </Body>
    </HTML>

  5. #5
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Can you provide a link to the page in question, please?
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  6. #6
    Join Date
    May 2004
    Posts
    78
    Warren's code worked. But I don't understand why Jona's didn't. The error was that object was expected, but it was alerady set thru parent.document.forms... ?

  7. #7
    Join Date
    Sep 2004
    Location
    Midwest
    Posts
    1,629
    I don't think it makes sense to try and control the property of a button that is an element of the main document by means of code that is in the source of the Iframe. My code controls the property of the Submit button by means of code solely within the main document.
    Last edited by Warren86; 10-27-2004 at 12:52 PM.

  8. #8
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    I'd appreciate it, Warren, if you used DOM methods/proper JavaScript and valid HTML. (Your code will most likely only work in IE, though I haven't tested it in other browsers.) It will help support standards in these fora, as well as increase compatibility between user agents. Please note, though, that I am glad you are a member of these fora and willing to help the members who post here.

    Camokat, it helps when a link to the page in question is provided, so that I can cater to your exact needs. The solution I provided should have worked, but it depends on the situation and how/where you are using the code.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles