function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bcgbcg 

how to display child windows value on parent window.

Hello ,

 

I want to display values of child window on parent window. e.g.  i have one page and when on that page when i click on textbox a new window popup. in that popu window some lookup fileds are present and i want when i slect value from tha lookup fields and click on save button. value wil be saved in record and it also display on that textbox in the parent window and popup window close after that.

 

Please anyone tell me how to fetch the values on parent window.

 

 

Thank in Advance.

sinsiterrulezsinsiterrulez

On clicking the textbox call a javascript method which calls new page where you have that lookup logic written. On selecting any value in child call a JS which will enter that value in parent page field.

Find the sample code:

 

//Function for parent page to open new page
function openclient()
{ 
    var value =   document.getElementById('{!$Component.page_id.form.fieldid}').value;
    window.open("{!$Page.childpage}?&ctvalue="+value,"lookup","width=750,height=500");     
    return false;    
}
///////////////////////////////////
//Function in child page to set value on parent page field
function setvalue(resultName)
       {
        window.opener.document.getElementById('page_id:form:fieldid').value = resultName;
        self.close();
        return false;     
       }

 Hope it helps

 

bcgbcg

Thanks for reply.... but i don't understand what is the result name here. am posting my code. pls check that code and then pls tell me what to do in that for displaying value in textbox of parent window and also its saved in record of my object.

 

Parent page:

 

<apex:page controller="TimeTable" >
<apex:form >
 <script>
        var myWindow;
        function move() {
            myWindow = window.open('/apex/TimeTable','','width=550,height=450');
        }
            </script><style>   
.cField
{        
width:100px;
height:60px;    
}
.bField
{        
width:30px;
height:30px;    
}

</style>

<apex:pageBlock >
<apex:pageBlockTable value="{!Period}" var="p" border="10" columnsWidth="200" width="500" >
<apex:column headerValue="Period Timing">
<apex:outputText value="{!p.Period_Timing__c}" styleClass="bField"/>
</apex:column>
<apex:column headerValue="MON">
<apex:inputField value="{!timetable.Set__c}" styleClass="cField" onclick="move();" />
</apex:column>
<apex:column headerValue="TUE">
<apex:inputField value="{!timetable.Set__c}" styleClass="cField" onclick="move();"/>
</apex:column>
<apex:column headerValue="WED" >
<apex:inputField value="{!timetable.Set__c}" styleClass="cField" onclick="move();"/>
</apex:column>
<apex:column headerValue="THU" >
<apex:inputField value="{!timetable.Set__c}" styleClass="cField" onclick="move();"/>
</apex:column>
<apex:column headerValue="FRI" >
<apex:inputField value="{!timetable.Set__c}" styleClass="cField" onclick="move();"/>
</apex:column>

</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 Child Page:

 

<apex:page controller="TimeTable" sidebar="false" id="mypage" showHeader="false" standardStylesheets="true">
<apex:form id="myform">
<apex:pageblock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Select The values">
<apex:inputField value="{!timetable.Teacher__c}" required="true" id="mytxtbox"/>
<apex:inputField value="{!timetable.Subject__c}" required="true"/>
<apex:inputField value="{!timetable.Room_No__c}" required="true"/>
</apex:pageBlockSection> 
</apex:pageblock>
</apex:form>
</apex:page>

 

Controller:

 

public class TimeTable
{
 public PageReference savenew(){
 PageReference pr;
  try { 
   
  PageReference sr = new PageReference('/apex/TestTimeTable');         
 sr.setRedirect(true);          
 return sr;
  }
 catch(Exception e) {  
 ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage()));   
 return null;  
}//try
 }//saveNew

    public List<Period__c> getPeriod()   
{  
return [SELECT Period_Timing__c FROM Period__c WHERE OwnerId = :UserInfo.getUserId() Order By Name ASC];      
}   

  public PageReference save()
        {
            try
                 {
                 insert timetable;       
                 }
            catch(System.DMLException e)
                 {
                     ApexPages.addMessages(e);  
                     return null;           
                 }
      PageReference pr=Page.TestTimeTable;
      pr.getParameters().put('id','timetable'); 
      return pr;
              
}

public PageReference cancel()
            {
                try
                 {
                    timetable=null;       
                 }
            catch(System.DMLException e)
                 {
                      ApexPages.addMessages(e);             
                 }
      return null;             
             }

public TimeTable__c timetable {get; private set;}
    {    
    Id id = ApexPages.currentPage().getParameters().get('id');
    timetable = (id == null) ? new  TimeTable__c () :
    [SELECT ID FROM TimeTable__c WHERE id = :id];
    }
   
    }

 

Please check ths and tell me how to do.

 

 

Thanks....

sinsiterrulezsinsiterrulez

Hi,

In child page resultname will be the value of inputfield which u need to populate on parent page.

So when you select value from lookup in the inputfield tage you can have onchange event & call setvalue method passing the value (this.value) as parameter.

 

Hope this solves your issue

YasirYasir

function check2(item) { alert('hello world = '+item); window.opener.location.href="/apex/customlookupinsertion?Id="+item; window.close(); }