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.



1 Answer 1


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

  • 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? Dec 17, 2013 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. Dec 17, 2013 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. Dec 17, 2013 at 13:47
  • 1
    @PramodKumar I think just use disabled and you are on the right way. Dec 17, 2013 at 14:38

You must log in to answer this question.

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