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

Open new VF page from Command Button on a VF page



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.



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 ="...URL TO your visual force page, try using {!$Page.PageName} to refer your page")







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();; }




 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.





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)
  if (msgWindow.opener=null)
  msgWindow.opener = self;
window.opener.updateValueFromPopup('parentId','user selected value from popup');
<input Type="button" value="Search" onClick=newWindow('','childwindow6');

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





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



<apex:page >
function updateValueFromPopup(elementId, newValue) {
 var parentElement = document.getElementById(elementId);
 parentElement.value = newValue;
<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;">

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



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