function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nishanth0208nishanth0208 

Disabling a field in input page based on a picklist value?

Hi Guys,

 

          I need help for a functionality in VF page to hide one of two fields based on picklist value in the same page.

 

             Here we have :     1)Opportunity type (PICKLIST) with options NEW, EXISTING.

                                            2)Opportunity LookUp

  3) Opportunity Name Text Field

 

Here, i need to disable the Opportunity Lookup if the picklist value is NEW. Sameway, i need to disable Opportunity Name text field, if the piklist value in EXISTING

 

                                 Please let me know whether i can do this or not,  suggest me the code to disable appropriate fields in my custom object's new record page.

 

 

   Tons of Thanks,

Nishanth.

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

There's a couple of ways to do this - one is to set the render attribute for the fields based on the value of the property backing the picklist. You'd need to have an onchange handler to submit the page back to the server.

 

The other is to use javascript and leave the fields there but disable/enable based on the selected value from the picklist.

All Answers

bob_buzzardbob_buzzard

There's a couple of ways to do this - one is to set the render attribute for the fields based on the value of the property backing the picklist. You'd need to have an onchange handler to submit the page back to the server.

 

The other is to use javascript and leave the fields there but disable/enable based on the selected value from the picklist.

This was selected as the best answer
nishanth0208nishanth0208

Thanks for the Knowldge. I did it using the Render and Onchange just now ... It works fine. And  may i know how can i do the same in JavaScript? (Just For Information)

bob_buzzardbob_buzzard

You can use the $Component global variable to locate HTML inputs on the page.  Once you have figured out the correct $Component value of the id, you can get the selected value from the select list and based on that enable/disable inputs.  

 

Something like:

 

var ele=document.getElementById('{!$Component.form.block.field');

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

if (opt='NEW')

{

    var newEle=document.getElementById('{!$Component.form.block.newfield');

    newEle.disabled=true;

}

mannnmannn

i am having picklist values like fresher and experienced, if fresher is selected the previous employee and experirnce text fields should be disabled , can u give code for this?

mmrrmmrr

I am new to salesforce, am getting errors in render, onchange etc.

The requirements is to enable a picklist field and make it mandatory based on  a checkbox.

Once the picklist field is enabled, if the picklist value=Common , I have to enable another field.  Javascript does not work out for me.

Can you please help me with the code. 

Mariappan PerumalMariappan Perumal

Hi bob,

 

Is it possible to do the same case for standard page instead of visualforce page.

bob_buzzardbob_buzzard

Not in any supported way.

 

Check out this blog post from Jason Venable which shows how to interact with the page from the sidebar:

 

http://www.tehnrd.com/show-and-hide-buttons-on-page-layouts/

.12.12
Hi All,
 
          I need help for a functionality in my datatable to hide one of the fields based on picklist value in the same datatable.
 
             Here we have :     1)Funding Options (PICKLIST) with Options Initial Investment,Initial and Monthly Investment
                                           2)Monthly Recurring Amount (input field type:currency)
                                           3)Start Date (input field type:date)

 
Here, i need to disable the Monthly Recurring Amount, Start Date  if the picklist value is Initial and Monthly Investment.
 
                                 Please let me know whether i can do this or not,  suggest me the code to disable appropriate fields in my custom datatable.
 
 
   Tons of Thanks,
Saiteja Gowd K.
 
Vijayakumar KenchugunduVijayakumar Kenchugundu
Hi .12,

I do have a similar requirement to be addressed. Did you find any resolution for your question? If so, please share your ideas.
Thanks
Vijay