I have one radio button and one inputfield..I am trying to achieve something like.if i click on the radio button , the input field should get active and user should be able to enter the value..If the radio button is not selected ..the field should be availabe but it should be disabled.

I have written something like below..but its not working

<input onclick ="document.getelementbyid('datepurchased').disabled =true;" type = "radio" name = "abc"></input>   
<apex:inputField id="datepurchased" value="{!lstRMA[0].Date_Purchased__c}"/>

can someone help?

  • ya sure !! are u getting any error ? Commented Jun 12, 2015 at 10:29
  • no error :( but it doesnot work Commented Jun 12, 2015 at 10:29
  • Can you use checkbox instead of radio button ? Commented Jun 12, 2015 at 10:32
  • i tried with checkbox..but still its not working Commented Jun 12, 2015 at 10:37
  • wait i'll provide you code Commented Jun 12, 2015 at 10:38

2 Answers 2


Here is a working example with Radio button. On load the input field is disabled, when you click on radio button the input field will enable.

VF Page

<apex:page standardController="contact" extensions="radioActionCtrl"  >
    <apex:form >
        <apex:selectRadio >
            <apex:actionSupport event="onchange" action="{!changeInputState}" rerender="opPanelName"/>
            <apex:selectOption itemValue="" itemlabel="Option1"/>
        <apex:outputPanel id="opPanelName">
            <apex:inputField value="{!contact.firstName}" id="NameInput" required="false"/>
                document.getElementById('{!$Component.NameInput}').disabled = {!disableInput};

Controller Extension

public class radioActionCtrl {
    public Boolean disableInput {get; set;}
    public radioActionCtrl(ApexPages.StandardController controller) {
        disableInput = true;
    public void changeInputState(){
        disableInput = false;

Hope this will help.


Here is a example...

<apex:pageBlock id="tBlock"> 
        <apex:outputLabel value="Checkbox" for="theCheckbox" />  
            <apex:inputCheckbox value="{!customObject.CheckBox__c}" id="theCheckbox">
                <apex:actionSupport event="onchange" rerender="tBlock"/>  

            <apex:outputLabel value="Enter Data Here" />  
            <apex:inputText value="{!customObject.TextField__c}" disabled="false" rendered="{!(customObject.CheckBox__c == true)}"/>  
            <apex:inputText value="{!customObject.TextField__c}" disabled="true" rendered="{!(customObject.CheckBox__c != true)}"/>  

            <!-- If you only want a field to show up when you check the box See below -->  
            <apex:inputText value="{!customObject.TextField__c}" rendered="{!(customObject.CheckBox__c == true)}"/>  

For additional information on the tag, you can go to the following link as well: http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_outputLabel.htm

I also use these pages for additional Visualforce reference: http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#CSHID=pages_compref_outputLabel.htm|StartTopic=Content%2Fpages_compref_outputLabel.htm|SkinName=webhelp

I hope this helps out.



  • what do you mean by !customObject.CheckBox__c Commented Jun 12, 2015 at 10:50
  • dear your checkbox field value which will come from object Commented Jun 12, 2015 at 10:51
  • i dont have checkbox_c in my custom object then how come it will come from database? Commented Jun 12, 2015 at 10:52
  • than how will u get checkbox value ? Commented Jun 12, 2015 at 10:54
  • i have just rendered the checkbox on the vf page.when i click on radio button or checkbox..the input field should get enabled Commented Jun 12, 2015 at 10:55

You must log in to answer this question.

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