1

I have an input field in apex given below

<apex:inputField value="{!paymentDetails.Amount__c}" onChange="enableLppAmount(this)" required="true" />

Also I have a simple input box

<input type="number" id="lppAmount" disabled="true"/>

I have the following javascript

function enableLppAmount(input){
    if(input.value.length > 0){
    document.getElementById("lppAmount").disabled=false;
    }
    else {
     document.getElementById("lppAmount").disabled=false;
    }
    }

Now When i enter any number in the apex input it is not enabling the html input. Basically the function is not being called. I want that when someone enters value in the apex input the simple input should be enabled and if no value then disabled. thanks for any help.

2 Answers 2

2

you have forget to apply semi coloun after calling javascript method

<apex:inputField value="{!paymentDetails.Amount__c}" onChange="enableLppAmount(this);" required="true" />

also script must be in

<script> function enableLppAmount(input){
    if(input.value.length > 0){
    alert(hi);
    document.getElementById("lppAmount").disabled=false;
    }
    else {
     document.getElementById("lppAmount").disabled=false;
    }
    }
</script>

tags

4
  • Also I had a problem which I was facing that above apex input field I had a button to add a row from the controller for the same record so that user can enter multiple amounts . The onchange works only on the first row amount inout field not on the other rows why is that so? Jun 6, 2016 at 16:50
  • I feel this is not right answer. There is no such requirement to add semi colon post function call in java-script. Jun 6, 2016 at 16:55
  • It worked for me Jun 6, 2016 at 16:57
  • Yes but with code given in question/answer it can never work. See revised answer. Jun 6, 2016 at 17:03
0

Here are the reasons why code was not working:

alert(hi);

This statement will treat 'hi' as a javascript variable and will try to find out 'hi' variable. As there is no 'hi' variable in code it will throw error and rest of the function will not work properly. Another problem:

 document.getElementById("lppAmount").disabled=false;

Same statement is written in if and else blocks. So Same behavior will be experienced for every change in input value.

1
  • Thank you for pointing that out that was actually a typo error I had put them inisde the "" brackets initially. I have removed them from the question though Jun 6, 2016 at 17:04

You must log in to answer this question.

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