• Mircea Marin
  • 0 Points
  • Member since 2018

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 0
Hi everyone,

We have a method that sets the value of a variable / field called {!input}. This value is then read in a JavaScript function which immediately sets the value of another field / variable {!output}. The problem is that in order to have the value of {!input} available for the JavaScript to read, the form needs to be reRendered first.
Can this be achieved with just one commandButton?

Apex Class
public String input {get; set;}
      public String output {get; set;}
public void generateInput() {
      input = ‘some calculated value’;
VF Page
<script type="text/javascript">
    function generateOutput(){
        var input = document.getElementById('{!$Component.input}').value;
        if(input) {
        var output = input + ‘some other value’;
        document.getElementById('{!$Component.output}').value = output;
<apex:form id="myForm">
    <apex:inputText id="input" value="{!input}"/>
    <apex:inputText id="output" value="{!output}"/>
    <apex:commandButton value="Generate Input" action="{!generateInput}" reRender="myForm"/>
    <apex:commandButton value="Generate Output" onclick="generateOuput()" reRender="myForm"/>
How can the 2 actions be done with one click? -> if we try to combine the action and onclick of the 2 commandButttons and use them on the same button, on the first click of the button the output is created and only on the second click the input.