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}');

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

1 Answer 1


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, 2013 at 15:37
  • @Udaya Sorry, i gave the wrong answer (simply overlooked :) Updated my code. May 28, 2013 at 16:58

You must log in to answer this question.

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