enter image description hereI have a InputTexField which has a custom lookup associated. Let's say I have associated three values A, B, C by opening lookup for First time. I have calling Javascript on the click of the OK which does A,B,C as association. Now I wanted to associate a different employee record so opened up the lookup second time and associated value say D. So in the inputText Field it should appear as A,B,C,D. My problem is that after opening second it erases the first time selection and it displays only D on click of 'Ok' button.

 <apex:pageBlockButtons location="bottom">
            <div align="Right" draggable="false">
                    <apex:commandButton value="Ok" id="selectEmp" onClick="selectAllEmployees();return false;"/>                        
                    <apex:commandButton value="Cancel" onclick="window.top.close()" />

Calling Javascript

 <script type="text/javascript">

function selectAllEmployees(){
    var selectedNames = [];
    var selectedIds   = [];
    function(v) {

 function closeAndPassParams(nameTosend,idToSend){
   var parent = window.opener.document;
   var targetField = parent.getElementById('{!$CurrentPage.parameters.namefield}');
   var targetField1 = parent.getElementById('{!$CurrentPage.parameters.idfield}');
   targetField.value = nameTosend;
   targetField1.value = idToSend;

You have to add the new values with old values before assigning to the Parent fields. Check if any validation is required for the first time when targetField and targetField1 are blank.

targetField.value = targetField.value + nameTosend;
targetField1.value = targetField1.value + idToSend;
  • Thank you. Not sure why my brain didn't think it to be simple rather over thinking :). – user28452 Feb 24 '17 at 9:55
  • I need to append comma after every name so I modified your code as targetField.value = targetField.value + ',' + nameTosend; But the problem here is it always append , as the first value. Like ,test@example.com,test1@example.com. I tried to remove the comma by validating targetField.Value in the if condition like If(targetField.value !== "undefined") but that didn't help. Any idea how would I remove that first comma? – user28452 Mar 6 '17 at 6:01
  • I was able to do this by targetField.value = targetField.value.replace(/^,/, ''); – user28452 Mar 6 '17 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.