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
LithiumsLithiums 

Apex Method invokation from Javascript

I am trying to call the method and pass the parameter, I can see that the method is getting invoked but  the value is not getting passed to the controller. Can someone please look at this and let me know if I am missing something.

 

VF Page:

<apex:page standardController="Opportunity" extensions="testcontroller">
<script type="text/javascript">
function testclick(Value){
testcheck(Value);
}
</script>
<apex:form >
<apex:actionFunction action="{!testmeth}" name="testcheck">
<apex:param assignTo="{!pValue}" value=""/>
</apex:actionFunction>
<apex:pageBlock >

<apex:inputCheckbox title="Test" id="chkbox" onclick="testclick('Test')"/>
<apex:outputLabel id="olabel" for="chkbox">Test</apex:outputLabel>
</apex:pageBlock>

</apex:form>
</apex:page>

 

Controller:

public class testcontroller{

public testcontroller(ApexPages.StandardController controller) {

}

public Static String pValue{get;set;}

public static void testmeth(){
system.debug('Test --->' + pValue);
}
}

Best Answer chosen by Admin (Salesforce Developers) 
Laxman RaoLaxman Rao

You are missing reRender in action function and name in param.

 

Try this:

 

<apex:page standardController="Opportunity" extensions="delete5">
<script type="text/javascript">
function testclick(Value){
testcheck(Value);
}
</script>
<apex:form >
<apex:actionFunction action="{!testmeth}" name="testcheck" reRender="chkbox">
<apex:param assignTo="{!pValue}" value="" name="someName"/>
</apex:actionFunction>
<apex:pageBlock >

<apex:inputCheckbox title="Test" id="chkbox" onclick="testclick('Test')"/>
<apex:outputLabel id="olabel" for="chkbox">Test</apex:outputLabel>
</apex:pageBlock>

</apex:form>
</apex:page>

All Answers

Laxman RaoLaxman Rao

You are missing reRender in action function and name in param.

 

Try this:

 

<apex:page standardController="Opportunity" extensions="delete5">
<script type="text/javascript">
function testclick(Value){
testcheck(Value);
}
</script>
<apex:form >
<apex:actionFunction action="{!testmeth}" name="testcheck" reRender="chkbox">
<apex:param assignTo="{!pValue}" value="" name="someName"/>
</apex:actionFunction>
<apex:pageBlock >

<apex:inputCheckbox title="Test" id="chkbox" onclick="testclick('Test')"/>
<apex:outputLabel id="olabel" for="chkbox">Test</apex:outputLabel>
</apex:pageBlock>

</apex:form>
</apex:page>

This was selected as the best answer
MagulanDuraipandianMagulanDuraipandian

<apex:param value="{!pValue}"/>

 

Use like this and check...

 

 

Regards,

Magulan D

Salesforce.com certified Force.com Developer.

 

SFDC Blog

 

If this post is your solution, kindly mark this as the solution.

LithiumsLithiums

Thanks a lot it worked, so rerender is a required attribute?

Laxman RaoLaxman Rao

yes, whenever the page gets refreshed all the paramters for the page gets refreshed.