You need to sign in to do that
Don't have an account?

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);
}
}
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
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>
<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.
Thanks a lot it worked, so rerender is a required attribute?
yes, whenever the page gets refreshed all the paramters for the page gets refreshed.