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
michael_hymichael_hy 

The issue on Ajax invoke via Js code.

Hi, guys.

 I met one issue on our project. 

ApplicantInformationController is a Apex class and loadHomeInfo() is a method in ApplicantInformationController.

So far when I click the checkbox, I want to invoke the loadHomeInfo(), but cannot successful.

 

Below is my code. Please help on this. thanks.

 

PS: the alert can popup, but CallActionFunctionForAddressSync is not run successful.

 

When first load the page, and click the checkbox, CallActionFunctionForAddressSync cannot run, but when click twice, CallActionFunctionForAddressSync can run successful.

 

Do anyone know why the method cannot run at first load?

 

<apex:inputCheckbox value="{!objApplicantInformationController.workAddress.IsSameAsHomeAddress__c}" id="IsSameAsHomeAddress" onclick="deselectOther(this);">      
                    </apex:inputCheckbox>  
                    
                    <apex:actionFunction name="CallActionFunctionForAddressSync" action="{!objApplicantInformationController.loadHomeInfo}" rerender="psec3" status="addressUpdateAction" oncomplete="alert('hi');">
                        <apex:param name="WorkIsHome" value=""/>
                    </apex:actionFunction>


<script type="text/javascript">

function deselectOther(chkBox)
    {  
        alert("checkBox_clicked");
        alert(chkBox.checked);
        var id;
        if(chkBox.checked)
        {
            id=chkBox.id;
            CallActionFunctionForAddressSync(1);
        }
        else
        {
            CallActionFunctionForAddressSync(2);
        }
        alert("deselect_other_complete");     
    }
</script>