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
Ap30Ap30 

how to change outputtext value

Hello All,

I have created a visualforce page and apex which is used to calculate values and display in visualforce page. In a scenario, output text value has to be changed. I'm new to this. Kindly help.

<apex:page Controller="xxCalculator">
  <apex:form >
    <apex:pageBlock title="xx Calculator">
  <apex:pageBlockSection >
  <apex:inputText label="Number of 1:" value="{!num1}"/><br/>
  <apex:inputText label="Number of 2:" value="{!num2}"/><br/>
  <apex:commandButton value="Calculate" action="{!yyCalculate}" reRender="{!changeOutput}"/>
  </apex:pageBlockSection>
  </apex:pageBlock>
  
  <br/>
  <font color="red">
   HERE YOUR OUTPUT is:<apex:outputText value="{!output1}" />
   </font>
  </apex:form>
</apex:page>


================

public class xxCalculator{

public String changeOutput{ get; set; }
public integer num1{set;get;}
public integer num2{set;get;}
public integer output1{set;get;}
public void yyCalculate(){
    if(num1 == 1 && num2 == 1)
    {
        output1 = 0;
    }
   
    else if(num1 > 1 && num2 > 1 )
    {
        output1= (10 * num1) + (15 * num2);
    }
       
    }  
    public PageReference changeOutput(){
    if(output1 > 60)
    {
        output1 = 60;
    }
    
    return null;
    }  
    
}
                    
 
Best Answer chosen by Ap30
Suraj Tripathi 47Suraj Tripathi 47
Hi Ap30,
Kindly find the solution.

Vf Page:
<apex:page controller="Example">
    <apex:form>
        <apex:pageBlock title="Calculator">
            <apex:pageBlockSection >
                <apex:inputText label="Number of 1:" value="{!num1}"/><br/>
                <apex:inputText label="Number of 2:" value="{!num2}"/><br/>
                <apex:commandButton value="Calculate" action="{!yyCalculate}" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    <apex:pageBlock title="Output" id="op">
        <font color="red">
            HERE YOUR OUTPUT is:<apex:outputText value="{!output1}" />
        </font>
    </apex:pageBlock>
</apex:page>

Apex Controller:
public class Example
{
    public String changeOutput{ get; set; }
    public integer num1{set;get;}
    public integer num2{set;get;}
    public integer output1{set;get;}
    public void yyCalculate(){
        if(num1 == 1 && num2 == 1)
        {
            output1 = 0;
        }
        else if(num1 > 1 && num2 > 1 )
        {
            output1= (10 * num1) + (15 * num2);
        }
        if(output1 > 60)
        {
            output1 = 60;
        }
    }  
}
If you find your Solution then mark it as the best answer. 

Thanks and Regards
Suraj Tripathi.

All Answers

Suraj Tripathi 47Suraj Tripathi 47
Hi Ap30,
Kindly find the solution.

Vf Page:
<apex:page controller="Example">
    <apex:form>
        <apex:pageBlock title="Calculator">
            <apex:pageBlockSection >
                <apex:inputText label="Number of 1:" value="{!num1}"/><br/>
                <apex:inputText label="Number of 2:" value="{!num2}"/><br/>
                <apex:commandButton value="Calculate" action="{!yyCalculate}" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    <apex:pageBlock title="Output" id="op">
        <font color="red">
            HERE YOUR OUTPUT is:<apex:outputText value="{!output1}" />
        </font>
    </apex:pageBlock>
</apex:page>

Apex Controller:
public class Example
{
    public String changeOutput{ get; set; }
    public integer num1{set;get;}
    public integer num2{set;get;}
    public integer output1{set;get;}
    public void yyCalculate(){
        if(num1 == 1 && num2 == 1)
        {
            output1 = 0;
        }
        else if(num1 > 1 && num2 > 1 )
        {
            output1= (10 * num1) + (15 * num2);
        }
        if(output1 > 60)
        {
            output1 = 60;
        }
    }  
}
If you find your Solution then mark it as the best answer. 

Thanks and Regards
Suraj Tripathi.
This was selected as the best answer
Ap30Ap30
Thanks. It's working.