www.webdeveloper.com
Results 1 to 7 of 7

Thread: Problem updating value in child window

  1. #1
    Join Date
    Dec 2008
    Posts
    4

    Problem updating value in child window

    Hi,

    I am having a problem updating a value in a child window and my scouring for a solution has been in vain.

    The routine simply opens a new window and populates a DIV with the value of of an entry (name passed as a parameter) in the parent form. This is the routine:

    function showHTMLSample(area){
    var newwin = window.open('/showHTML.html', area,'width=700,height=400,resizeable,scrollbars');
    newwin.document.getElementById('showHTML').innerHTML = document.getElementById(area).value;
    newwin.focus();
    return false;
    };


    Error console (FF 3.0.4) shows the message "newwin.document.getElementById('showHTML') is null".

    Strangely, if I put in an alert directly after the open (as below) everything works perfectly!

    function showHTMLSample(area){
    var newwin = window.open('/showHTML.html', area,'width=700,height=400,resizeable,scrollbars');
    alert('Press OK');
    newwin.document.getElementById('showHTML').innerHTML = document.getElementById(area).value;
    newwin.focus();
    return false;
    };


    Any help or advice greatly appreciated

    TIA

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Change 'showHTML' after the document has loaded. Update from the child not the parent.
    Last edited by Fang; 12-15-2008 at 08:07 AM.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Dec 2008
    Posts
    4
    Thanks for the reply Fang - but I had wanted to use this approach since I didn't want to force a standard variable or element in each parent document.

    Also, I am really curious as to why this isn't working - or why it works after the delay.

    I have tried a wait loop until the element isn't null and also adding a listened to wait until the child window is loaded - but neither work.

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    function showHTMLSample(area){
    var newwin = window.open('showHTML.html', area,'width=700,height=400,resizeable,scrollbars');
    try { // IE
        newwin.document.getElementById('showHTML').innerHTML = document.getElementById(area).value;
        }
    catch(e) { // Fx
        newwin.onload=function(){newwin.document.getElementById('showHTML').innerHTML = document.getElementById(area).value;}
        }
    newwin.focus();
    return false;
    }
    At least 98% of internet users' DNA is identical to that of chimpanzees

  5. #5
    Join Date
    Dec 2008
    Posts
    4
    Excellent Fang! Thank you.

    Works perfectly for Firefox but no luck with IE :-(

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Worked for me in IE7. Try a waiting loop for the element to load in IE.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  7. #7
    Join Date
    Dec 2008
    Posts
    4
    Many thanks Fang - the wait loop works fine.

    Obviously something to do with the length of time it takes for the child window to become available.

    Your help is greatly appreciated!

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