0

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?

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

2 Answers 2

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:selectRadio>       
        <apex:outputPanel id="opPanelName">
            <apex:inputField value="{!contact.firstName}" id="NameInput" required="false"/>
            <script>
                document.getElementById('{!$Component.NameInput}').disabled = {!disableInput};
            </script>
        </apex:outputPanel>            
    </apex:form>
</apex:page>

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.

1

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:inputCheckbox>   

            <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)}"/>  
    </apex:pageBlock>  

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.

Thanks!

Aryan!

7
  • what do you mean by !customObject.CheckBox__c Jun 12, 2015 at 10:50
  • dear your checkbox field value which will come from object Jun 12, 2015 at 10:51
  • i dont have checkbox_c in my custom object then how come it will come from database? Jun 12, 2015 at 10:52
  • than how will u get checkbox value ? 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 Jun 12, 2015 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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