3

VF page to enable one of two fields based on picklist value in the same page. Please verify my code whether is right or worng. I am running this code but nothing happen.

<apex:page standardController="Account">

    <script type="text/javascript">
        function changetextbox(){
            var ele=document.getElementById('{!$Component.form1.block1.populate}');
            var opt=ele.options[ele.selectedIndex];
            if (opt=='Prospect'){
                var newEle=document.getElementById('{!$Component.form1.block1.textpop}');
                newEle.enabled=true;
            }
        }
    </script>

    <apex:form id="form1">
        <apex:pageBlock id="block1">
            <apex:inputField value="{!Account.Type}" id="populate" onchange="changetextbox();"/>
            <apex:outputField value="{!Account.accountnumber}" id="textpop"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>
0

I think the error here is that you must specify what parameter of the selected option you want to get: value or text

For example the selected option looks like:

<option value="1">My Option</option>

To get the text My Option you need the following code:

var opt = ele.options[ele.selectedIndex].text;

And to get a value 1:

var opt = ele.options[ele.selectedIndex].value;

But what surprises me in your code is that you try to enable the output field. The output field is just a text block und could not be enabled?

  • thanks for reply Sergey . i had modify a code but nothing happen – Udaya May 28 '13 at 15:37
  • @Udaya Sorry, i gave the wrong answer (simply overlooked :) Updated my code. – Sergej Utko May 28 '13 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.