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
Chandra Kant BaghelChandra Kant Baghel 

Apex to Javascript and Javascript to Apex Communication?

Hi All,

I have a requirement in which I have to communicate back and forth between apex and javascript.
The initial step being in apex should then call javascript based on some condition check, that  javascript will do some processing and will then call apex and that will again call Javascript and then apex.

Can somebody suggest how to maintain the control flow ?
mukesh guptamukesh gupta
Hi Chandra, 

please follow below steps:-

A component that provides support for invoking controller action methods directly from JavaScript code using an AJAX request. An component must be a child of an component.


<apex:commandButton value="Search" onclick="check();" reRender="nPbt" />
 
function check(){
    var user = document.getElementById('pg:frm:nPB:ip').value;
    if(user == ''){
        alert('Please Enter noise Name before Proceeding.');
        return true;
    }
    else
        noiseSearchAF();
        return true;
   }
 
<apex:actionFunction action="{!noiseSearch}" name="noiseSearchAF" rerender="nPbt">

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 
Chandra Kant BaghelChandra Kant Baghel
Hi Mukesh,

Thanks for the reply,

I think you are are calling Apex from Javascript.
And that too on a button click.
I have to first call javascript from apex.