Pop Up Window

Discussion in 'JavaScript and AJAX' started by prashantSum, Nov 14, 2005.

  1. prashantSum

    prashantSum New Member

    Joined:
    Oct 24, 2005
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    0
    hi,
    I don't know exactly where to post this exactly, please forgive if I should not have posted it here.

    I have a problem, I have to open a popup window in which I have to show some check boxes, now when the user selects some check boxes I want get these values back to the window from where the popup window has been opened.

    how can I do this.. I am using J2EE on the server side, does request has to sent back to server,.. or can I do it in some other way...

    please help me...
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,376
    Likes Received:
    388
    Trophy Points:
    83
    This can be done using the plain JavaScript and does not need to be passed to the server. You can just write a JS function to reflect the changes from the child to the parent in the following manner

    Code:
    <script language="javascript">
    function reflect()
    {
    	parent.opener.window.document.<FormName>.<FieldName>.value = document.<ChildFormName>.<Field>.value;
    	return true;
    }
    </script>
     
  3. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    To pass on some values to the "opener" window from the "opened" window, you have to use the window.opener object.

    Example:
    Code:
    //in the original window
      var bValueFromPopup = false;
      document.form.myForm.button.onClick=function()
      {
         window.open("pop.htm","testt");
      }
      
      //this opens the file pop.htm in a new pop-up window.
      
      //in pop.htm, if you want to change/pass a value to the orginal window
      document.form.newForm.myButton.onClick=function()
      {
         window.opener.bValueFronPopup=true;
      }
      
      //this will change the value of the variable bValueFronPopup in the main window.
    You got the logic, hope now u can work on your problem.In case of any prob, dont worry, I am just a mouse click away ;-)

    ----------------------------------
    Computers are like airconditioners, if you open WINDOZE they don't function!

    http://spradeep.blogspot.com
     
  4. prashantSum

    prashantSum New Member

    Joined:
    Oct 24, 2005
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    0
    thx for the replies,

    I got that it....

    one more thing is, I have some check boxes in the popup window, now when select some check boxes in the that window and close that window and again open it check boxes which I have selected previously are not persisted (they are again coming to non select state)..

    how can we persist those selections until the parent form is submmited
     
  5. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Yes, you can do that, all you have to do is read the data from the main page,using the same logic.
     
  6. prashantSum

    prashantSum New Member

    Joined:
    Oct 24, 2005
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    0
    thx for the replies,

    parent.opener.window.document.<FormName>.<FieldName>.value = document.<ChildFormName>.<Field>.value;

    now the above code is working fine when I opened a window with window.open

    but...
    it's not working when I open a MODAL window....

    with window.showModalDialog(....)

    does it not work with the modal windows or do I need to change some code
     
  7. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    parent.opener wont work with showModalDialog, 'cause its not a pop-up window, its a dialog.You can pass & retrive values in ModalDialog too, for more help on that check this link http://www.webreference.com/js/column90/3.html
     
  8. prashantSum

    prashantSum New Member

    Joined:
    Oct 24, 2005
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    0
    thx pradeep,

    I got it.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice