+ Start a Discussion
udayar_jayamudayar_jayam 

Disabling a field in input page based on a picklist value

Hi All,

    

     VF page to hide one of two fields based on picklist value in the same page.plz verify my code is right or worng.im run this  code 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.disabled=true;
}
}
</script>
<apex:form id="form1">
<apex:pageBlock id="block1">
<apex:inputField value="{!Account.Type}" id="populate" onchange="changetextbox();"/>
<apex:inputField value="{!Account.accountnumber}" id="textpop"/>
</apex:pageBlock>
</apex:form>
</apex:page>

Best Answer chosen by Admin (Salesforce Developers) 
JohnSchultzJohnSchultz

You were close. You just need to change one line and it will work:

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

 Add the .text to the end of that line like I did above, and it will work.

All Answers

JohnSchultzJohnSchultz

You were close. You just need to change one line and it will work:

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

 Add the .text to the end of that line like I did above, and it will work.

This was selected as the best answer
udayar_jayamudayar_jayam

thanks for reply JohnSchultz its working fine but i have one more doubt in opportunity Stage field when i select "closed won". then all the fields closed won pageblocksection will be display in VF otherwise it will be disable.