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
Puneet SardanaPuneet Sardana 

Problem with action function oncomplete event

I am performing some validation on click of button


<apex:commandButton styleClass="cmdButton" style="background: green;" value="{!if(timesheet3.Status__c == 'To Be Approved','Verify Timesheet','Approve Timesheet')}" onclick="javascript&colon;displayHoursPerWeekError('{!hoursPerWeekError}')" rerender="msg" />


function displayHoursPerWeekError(display)

var agree=confirm("Hours per week is less, are you sure you want to submit timesheet?");
if (agree)
return true ;
return false ;
return true;

If validation is true then I am calling submitApprove function at the controller using action function. Now after completing the request I need to get a property defined at controller to determing whether to close the window or not. But the alert('{!Test}'); prints blank although for testing purpose I am just returning false from this property.


<apex:actionFunction action="{!submitApprove}" oncomplete="Javascript&colon;alert('{!Test}');if('{!closeWindow}' == 'true') {window.close();};"  name="approval"/>


You should probably instead use a partial update:


function onCompleteHandler() {
  var successElement = document.getElementById('{!$Component.form.success}');
  if(successElement.value=='true') {

<apex:form id="form">
<apex:inputHidden id="success" value="{!success}"/>
<apex:actionfunction action="{!submitapprove}" oncomplete="onCompleteHandler()" name="approval" reRender="success"/>

I personally just return them to a new page whose only purpose is to close the window. Less fuss.

Redirecting to new page is not a good solution. What we don't want to display another page or this page is opened as a new window/tab and closing this tab will take user back to previous page.

I am using console and we just want to close tab. No redirect / return to new page.