I 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()" />
</div>
</apex:pageBlockButtons>
Calling Javascript
<script type="text/javascript">
function selectAllEmployees(){
var selectedNames = [];
var selectedIds = [];
[].forEach.call(document.querySelectorAll('input:checked'),
function(v) {
selectedNames.push(v.dataset.fullName);
selectedIds.push(v.dataset.emailValue);
alert(selectedNames);
alert(selectedIds);
});
closeAndPassParams(selectedNames,selectedIds);
}
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;
self.close();
}
</script>