<apex:form >
  <apex:variable value="{!0.00}" var="total1"/>

    document.getElementsByClassName('t1')[0].innerHTML = '{!total1}';

          <apex:outputText value="{!z.price}"/>
          <apex:variable var="total1" value="{!total1 + z.price * z.qtyToBuy}"/>
                   <apex:facet name="footer">
                   Total: $<span class="t1"></span>


I have an apex variable total1 declared on my VF page. I would like to pass this total1 var into my apex controller on rerender. How do I pass that?

Thanks guys!


Here's a convoluted, but working example:


public class passvar {
    public decimal totalValue { get; set; }
    public passvar() {
        totalValue = 5;


<apex:page controller="passvar">
    <apex:form id="form">
        <apex:variable value="{!10.00}" var="total"/>
        <button onclick="something({!total}); return false">
            Update Value
        <apex:actionFunction reRender="form" name="something">
            <apex:param assignTo="{!totalValue}" value="" name="totalValue"/>
        {!totalValue}: {!total}

Some notes:

  • You need to reRender, or totalValue won't be updated correctly.
  • Value attribute on the param is intentionally blank (it's provided by the function).
  • Value will be placed inline at the moment the function is rendered. This means it should work correctly inside repeats, etc.

The way you're doing it in your example wouldn't work, because {!total1} will be the value at the time of rendering (i.e. not set from the second value). Your script would have to read the value after the second setting of total1. There's probably a better way to do what you're trying to do.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.