Passing element values from parent window to child popup window and vice-versa

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pingalkar
    New Member
    • Feb 2007
    • 6

    Passing element values from parent window to child popup window and vice-versa

    Hi,
    In my application, I call one popup winodow by using this link..

    [HTML]<a href="#" onClick="return showWindow('1', 'XYZ');">
    <img src="images/magnifier.gif" ALT="Chemicals" width=18 height=20 border=0>
    </a>[/HTML]

    In this showWindow function....
    [CODE=javascript]
    var newWindow = '';
    var url='jsp/DEPO/Chemicals/ProductConfigTa bs.jsp';
    function showWindow(data 1, data2)
    {
    if (!window.focus) {return true;}
    if (!newWindow.clo sed && newWindow.locat ion)
    {
    newWindow.locat ion.href = url;
    }
    else
    {
    newWindow=windo w.open(url+'?ab c=ABC&Id='+data 1,'NewWin','too lbar=no,status= yes,width=520,h eight=440');
    if (!newWindow.ope ner) newWindow.opene r = self;
    //Set value into Child window element.
    setTimeout("Sen dToChild('" + data1.toLocaleS tring() + "','" + data2.toLocaleS tring() + "')",20);
    if (window.focus){ newWindow.focus ();}

    }
    }

    //Pass value to child window..
    function SendToChild(dat a1,data2)
    {
    //Set Hidden value into child Window
    newWindow.docum ent.getElementB yId("hiddenDivI d1").value=data 1;
    newWindow.docum ent.getElementB yId("hiddenDivI d2").value=data 2;
    }[/CODE]

    //In child window JSP i use this div for storing parent window passed values.

    [HTML] <div id='hiddenDivId 1'></div>
    <div id='hiddenDivId 2'></div>
    [/HTML]
    ** But Some time i can access this hidden div of child window and some time not..
    Please help me to pass parent window element values to child and vice-versa Or Any other way to pass value,
    like what i did with url, by using parameter.. please check is this way correct to pass and get value in request

    [HTML]<input type="hidden" name="Id" id="Id" value="<%=reque st.getParameter ('Id')%>">[/HTML]

    Please use code tags when posting code - moderator

    I dont know what i am doing wrong in it. please help me in this problem.

    Thanks,
    Gajendra
    Last edited by acoder; Jul 20 '07, 09:59 AM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Move the declaration of newWindow outside the function to make it a global variable. If you need to reset it, do not use the var keyword.

    When trying to set the content in a div, "value" won't work. Use innerHTML instead or create a text node and append it to the div.

    To access the parent from the child, use window.opener.

    Comment

    Working...