Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using apex:selectList component and trying to make it readonly by setting its readonly property like below -

<apex:selectList value="{!state}" multiselect="false" size="1" id="state" readonly="true">
<apex:selectOptions value="{!stateOptions}"/> 

I am setting its value using one javascript function dynamically something like below -

document.getElementById('j_id0:frm:j_id10:j_id21:pbtCostDetails:state').value = 'Jaipur';

problem is it is not getting readonly. User is able to select any value in select list.


share|improve this question
If I recall correctly it's nothing wrong with Visualforce, it's the <select> HTML tag that's bit quirky to use. Check… or, inspect the generated HTML in the browser... – eyescream Dec 17 '13 at 9:11
up vote 7 down vote accepted

There is some difference between readonly and disabled parameters.

If you want to show the picklist visually as disabled on the page you need to use disabled="true" parameter.

If you want, that selected value will not transmitted to the controller you need to use readonly="true".

Here is a test page. Just testing it.

<apex:pageBlock mode="edit" title="Selection" tabStyle="Account">
        <apex:commandButton value="Submit"/>
        Selected Value:<apex:outputText value="{!output}"/>

    <apex:pageBlockSection columns="1" showHeader="false" collapsible="false">
        <apex:outputLabel value="Select:" for="state"/>    
        <apex:selectList value="{!output}" multiselect="false" size="1" id="state" readonly="true">
            <apex:selectOption itemLabel="Option 1" itemValue="Option 1"/>
            <apex:selectOption itemLabel="Option 2" itemValue="Option 2"/>


1) Readonly = true
After submition the value from the picklist is not transferred to the controller. enter image description here

2) Readonly = false
The value successfuly transferred. enter image description here

2) Disabled = true
The picklist is completely disabled.

enter image description here

share|improve this answer
As per your reply, in both the cases "disabled" and "readonly" values don't submit to controller. but i read somewhere that in case of "disabled" value doesn't get transferred to controller but in case of "Readonly" values get transferred to controller. Can you please confirm? – Pramod Kumar Dec 17 '13 at 11:11
It is not directly documented (is it?). The documentation says: If set to true (readonly), the list option selections cannot be changed. I've tried it on my dev org and if readonly is set to true then i cannot get the selected value in controller. – Sergey Utko Dec 17 '13 at 12:15
I am not sure about the salesforce specifically. but html code work like this. "ReadOnly" gets submitted to server but "Disabled" doesn't. I am not sure then where should i use "Readonly=true" property. – Pramod Kumar Dec 17 '13 at 13:47
@PramodKumar I think just use disabled and you are on the right way. – Sergey Utko Dec 17 '13 at 14:38
You are right. Thanks a lot – Pramod Kumar Dec 17 '13 at 14:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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