1

I am trying to enable and disable one picklist field based on another picklist field. Here is the piece of code through which i am trying to achieve that

<script>
    function Compchange(){
        alert('Hello');
      document.getElementById('{!$Component.CompLostTo}').disabled = false;
    }
</script>

                <apex:inputField value="{!closeOppObj.Competitor__c}" onchange="Compchange();"/>
                <apex:inputField value="{!closeOppObj.Competitor_Lost_To__c}" id="CompLostTo" /> 
                <script>document.getElementById('{!$Component.CompLostTo}').disabled = true; </script>

i am facing issue with the document.getElementById('{!$Component.CompLostTo}').disabled = false; syntax which is inside the function Compchange(), is it not working as expected. Please suggest how to resolve .. any suggestion will be highly appreciated.

1 Answer 1

0

For the disabled attribute, all that matters is it's presence or absence; the specific value doesn't matter. You can get rid of it with the removeAttribute function.

Also, judging by the indentation in your question, it looks like your function might be at a different level in the hierarchy and you need to reference the component with the id path for $Component to get the DOM id.

<script>
    function Compchange(){
       document.getElementById('{!$Component.theForm.thePageBlock.CompLostTo}').removeAttribute('disabled');
    }
</script>
    <apex:form id="theForm">
        <apex:pageBlock id="thePageBlock" >
                <apex:inputField value="{!closeOppObj.Competitor__c}" onchange="Compchange();"/>
                <apex:inputField value="{!closeOppObj.Competitor_Lost_To__c}" id="CompLostTo" /> 
                <script>document.getElementById('{!$Component.CompLostTo}').disabled = true; </script>
1
  • Tried doing the same but still facing the same issue. Also i can see that the alert statement inside the function is working fine, only issue is happening with removeattribute syntax. Sep 4, 2018 at 9:33

You must log in to answer this question.

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