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
Hardik ChavdaHardik Chavda 

How can I use <apex:param> value as a parameter in javascript function?

Following is my code.
<apex:actionFunction action="{!BusinessPartnering}" name="BusinessPartnering" oncomplete="onPageRerender();endProcess();ChangeBackgroundColor(//pass the value of <apex:param>');" reRender="AssessmentBody">
            <apex:param name="firstParam" assignTo="{!FunctionalAreaParam}" value="" />
        </apex:actionFunction>

Now here, I want to pass the <apex:param> value as a argument in ChangeBackgroundcolor() method. Can anyone help me with this?
Best Answer chosen by Hardik Chavda
Alexandre BenitaAlexandre Benita
Hi,

I think you can directly bind the function ChangeBackgroundcolor to your actual param.

Try writing something like this :
<apex:actionFunction action="{!BusinessPartnering}" name="BusinessPartnering" oncomplete="onPageRerender();endProcess();ChangeBackgroundColor('{!FunctionalAreaParam}');" reRender="AssessmentBody">
            <apex:param name="firstParam" assignTo="{!FunctionalAreaParam}" value="" />
</apex:actionFunction>

Regards,

Alexandre

All Answers

Amit Chaudhary 8Amit Chaudhary 8
You can user param tah with action function like below :-
Example 1:-
<apex:outputLink value="javascript:if (window.confirm('Are you sure?')) DeleteQuoteLineItem('TEST VALUE');">
    Del
</apex:outputLink>

    <apex:actionFunction action="{!DeleteQuoteLineItem}" name="DeleteQuoteLineItem" reRender="content">
        <apex:param name="myParam" value=""/>
    </apex:actionFunction>

Example 2:-  Please check below blog
http://www.cloudforce4u.com/2013/09/passing-parameters-in-action-function.html

Example 3:- 
http://www.salesforceworld.blogspot.in/2011/06/parameter-passing-using.html#!http://salesforceworld.blogspot.com/2011/06/parameter-passing-using.html
In visualforce, there is a method for passing parameters from visualforce page to controller using javascript and actionFunction. Here is the example;

/*JavaScript*/
<script type="text/javascript">
function doSave(date)
{
paraFunction(document.getElementById(date).value);
}
</script>

/*Action Function*/
<apex:actionFunction name="paraFunction" action="{!saveInterviewDate}" rerender="view"> <apex:param id="aname" name="interviewDate" value="" />
</apex:actionFunction>
/*Call the javaScript from here*/

<apex:commandLink onclick="doSave('{!$Component.interviewDate}');"> <apex:commandButton value="Save"/> </apex:commandLink>
/*get the parameter in controller*/
String interviewdate=Apexpages.currentPage().getParameters().get('interviewDate');

Please let us know if above solution will help u.

Thanks
Amit Chaudhary
Alexandre BenitaAlexandre Benita
Hi,

I think you can directly bind the function ChangeBackgroundcolor to your actual param.

Try writing something like this :
<apex:actionFunction action="{!BusinessPartnering}" name="BusinessPartnering" oncomplete="onPageRerender();endProcess();ChangeBackgroundColor('{!FunctionalAreaParam}');" reRender="AssessmentBody">
            <apex:param name="firstParam" assignTo="{!FunctionalAreaParam}" value="" />
</apex:actionFunction>

Regards,

Alexandre
This was selected as the best answer
Hardik ChavdaHardik Chavda
Hi Amit,
Thanks for the reply, But I think you don't get my question here. I know how to use apex:param but What I wanted is that how to use apex:param value in javascript function as a parameter? and the value which will be passed in param shall be used in javascript function parameter dynamically.
Hardik ChavdaHardik Chavda
Thanks Alexandre Benita, It worked. :)