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
DeepakKapoor81DeepakKapoor81 

Open new VF page from Command Button on a VF page

Hi,

 

I have requirement where in onclick of command button a Pop-up VF is required to open where in user will Find the new user using the Custom application which i have already developed in Apex and VF.

 

Now the User which comes as a result of search on new VF page, User will select the checkboxes in front of them and click save.

 

On click of Save, the new window should get closed and the selected on the selected user should get added onto the previous page from where i opened the VF page of searching the user.

 

Any help will be greaatly appreciated.

 

Thanks

Abhinav GuptaAbhinav Gupta

This is too big to answer. Still I will give you handles.

 

To do this, first of all "Command button" will not be the right choice. Use normal

 

<input type="button" ... onclick="function showPopup()" />

 

<script language="text/javascript">

var popupHandle; // handle to the popup window

function showPopup() {

 

 popupHandle = window.open("...URL TO your visual force page, try using {!$Page.PageName} to refer your page")

 

}

</script>

 

 


 

You can add onClick handler to the button.

 

 

the page which is opening the pop up is parent window. So you need to declare some javscript variable or function that your pop up window can access. 

 

For ex.  this function could go in parent window, this will be used by popup window's JS code to pass in the "newValue" to parent.

 

function updateValueFromPopup(elementId, newValue) { var parentElement = document.getElementById(elementId); parentElement.value = newValue; parentElement.focus(); parentElement.select(); }

 

 

 

 Now your popup can do whatever stuff it wants, then finally when your value is ready to be passed. Just execute the following code

 

 

window.opener.updateValueFromPopup('parentId','user selected value from popup');

 

 Hope this helps.

 

 

 

anu_karthianu_karthi

Hi iam having a similar issue and your post  was great and i tried it to solve my issue but i need some clarifications as iam not able to pass the value from my popup window to the child window my code for parent window and popup window is as follows ..please have alook and help me if iam going wrong...

 

My parent window with a search button opening   to popup window is as follows...

<apex:page >
<script language="javascript">
function newWindow(file,window)
{
  msgWindow=open(file,window,'scrollbars=yes,resizable=no,width=550,height=400');
  if (msgWindow.opener=null)
  msgWindow.opener = self;
}
window.opener.updateValueFromPopup('parentId','user selected value from popup');
</script>
<input Type="button" value="Search" onClick=newWindow('https://chiranjeevi.ap1.visual.force.com/apex/childwindow6','childwindow6');

<form name="inputform1" >
 <table><tr><td>Stitching Number
 </td>
 <td><input type="text" name="txtasno" id="input1" tabindex="1"  size="20">
 </td>
 
 </tr></table>
 </form>

</apex:page>

 

 

 

and my popup window is follows with a input text which i trying to pass to parent wiundow :

 

 

<apex:page >
<script>
function updateValueFromPopup(elementId, newValue) {
 var parentElement = document.getElementById(elementId);
 parentElement.value = newValue;
 parentElement.focus();
 parentElement.select();
 window.opener.updateValueFromPopup('input1','opener.document.outputform1.c_name.value');
 self.close();
 
}
</script>
<form name="outputform1">
<table border=0 cellpadding=0 cellspacing=0 width=250>


<tr><td align="center"> Your name<input type="text" name="c_name" size=12 value=test>
 <body onload="updateValueFromPopup()"  style="font-family: Arial;border: 0 none;">
 </td>
 </tr>

<input Type="button" value="Pass Value" onclick="updateValueFromPopup(input1,opener.document.outputform1.c_name.value);">


</form>
</apex:page>

 

SO please help me in  solving thwe issue....

 

 

                                                                                                                                                                                                   Thanks&Regards,

                                                                                                                                                                                                        Anu.....