[SalesForce] Perform action when Input Value is changed

I have an input box and I would like it to call a function whenever the value is changed, is that possible? I have tried:

 <div class="slds-form-element__control" id="annn">
      <apex:form ><apex:actionfunction name="onchangemethod" action="{!valueupdate}" rerender="annn"></apex:actionfunction>
      <input type="text" id="InptAnnVol" class="slds-input" value="{!InptAnnVol}" onchange="onchangemethod()"/></apex:form>
 </div>
Controller:
public void valueupdate(){
        decimal test;
        test = decimal.valueof(InptAnnVol);
        InptAnnvol = test.format();

    }

Best Answer

You need to call a action function when ever something changes in the text field. You need to send that value to controller method using apex:param

VF:

  <apex:actionfunction name="onChangeActMethod" action={!valueupdate} rerender="refreshing">
<apex:param name="valFromVf" value=""/>
</apex:actionFunction>

<input type="text" id="input-id-02" class="slds-input" value="{!InptAnnVol}"  onchange="onChangeActMethod(this.value);"/>

Controller:

public void valueupdate(){
    string x=Apexpages.currentPage().getParameters().get('valFromVf');
    decimal test;
    test = decimal.valueof(x);
    InptAnnvol = test.format();

}
Related Topic