My requirement is:

On the click of a command button, I need to call a controller method and set a value to a controller variable. After that assignment is done, oncomplete attribute of actionfunction should call the javascript code which uses that controller variable value which was set when we clicked on the button. When I did debug the the value using console.log, I don't see any value and it is showing as null. But the Debug statement in the controller is showing the value as expected.

The value is is not passed to VF page JS code. Please let me know if I am doing any wrong in the code. Here's the snippet of the code.

// Javacript Code
<script type="text/javascript">

function secondary ( action) {
   var url;
    if ( action == 'Provider' ) {
        url = "{!MWUrl}";
        console.log('URL ===='+url);       


<apex:actionFunction name="mWProviderSearchURL" action="
{!mWProviderSearchURL}" rerender="form" oncomplete="secondary('Provider');" 
<apex:commandButton onclick="mWProviderSearchURL(); return false;">

public class exampleController {

  public String MWUrl {get; set;}

  public void mWProviderSearchURL() {

    MWUrl = 'https://www.google.com';
  • Is your <script> inside the form? If not, it won't get the freshly rerendered value. May 16, 2017 at 1:46
  • hang on... you need to make MWUrl a string. Currently it's not defined May 16, 2017 at 1:50
  • Or it has a type, but no var name. Not sure how that code compiled - or was that a typo? May 16, 2017 at 1:51
  • @CasparHarmer I have edited the code to declare it as String. <Script> is inside form. I just added part of code to make it look simple. May 16, 2017 at 1:55
  • Try changing the command button to a regular button - you don't need a command button since you have an actionfunction May 16, 2017 at 1:56

1 Answer 1


If you Javascript is outside of your rerender target, then the value won't be refreshed on completion of your server call.

Move the <script> tag inside the form to ensure that it gets rerendered or add it to an outputPanel and add that to the rerender target.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .