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
sk kumarsk kumar 

how to create diffrent check box in lead object lie a,b,c & when i click check in certain checkbox a text box will appear next to checkbox & when i will uncheck the checkbox , textbox it will disapear

anyone tell me the logic or provide the code for this requirement..thnx in advance
Best Answer chosen by sk kumar
lakslaks
Hi Kumar,

You can check the below code, where there are 4 checkboxes.

On click of the last checkbox - Other, a textbox appears.
 
<apex:page controller="PageController">
    <apex:form >
      <apex:selectCheckboxes value="{!certVals}">
          <apex:selectOptions value="{!items}"></apex:selectOptions>
          <apex:actionSupport reRender="othercert" event="onchange" action="{!othercheck}"/>          
      </apex:selectCheckboxes> 
      
     <apex:outputPanel id="othercert">
         <apex:inputText rendered="{!showField}" value="{!otherCertVal}"></apex:inputText>          
     </apex:outputPanel>
      
    </apex:form> 
</apex:page>
 
public with sharing class PageController 
{

    public String otherCertVal { get; set; }
    
    String[] certVals = new String[]{};
    
    public Boolean showField{ get; set; }
    
    public PageController()
    {
        showField = False;
    }
    
    public List<SelectOption> getItems() 
    {        
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Salesforce Admin','Salesforce Admin'));
        options.add(new SelectOption('Salesforce Advance Admin','Salesforce Advance Admin'));
        options.add(new SelectOption('Salesforce Developer','Salesforce Developer'));
        options.add(new SelectOption('Other','Other'));
        return options;
    }
    
    public String[] getcertVals() 
    {
        return certVals; 
    }
    
    public void setcertVals(String[] certVals)
    {
        this.certVals = certVals;
    }
    
    public pageReference othercheck()
    {                
        if(!certVals.isEmpty() && certVals[0].equalsIgnoreCase('Other'))
        {            
            showField = TRUE;            
        }
        else if(certVals.isEmpty())
        {
            showField = False;  
        }
        else
        {
            showField = False;  
        }
        return null;
    }
    
}

Hope this helps.

Regards,
Lakshmi.

All Answers

lakslaks
Hi Kumar,

You can check the below code, where there are 4 checkboxes.

On click of the last checkbox - Other, a textbox appears.
 
<apex:page controller="PageController">
    <apex:form >
      <apex:selectCheckboxes value="{!certVals}">
          <apex:selectOptions value="{!items}"></apex:selectOptions>
          <apex:actionSupport reRender="othercert" event="onchange" action="{!othercheck}"/>          
      </apex:selectCheckboxes> 
      
     <apex:outputPanel id="othercert">
         <apex:inputText rendered="{!showField}" value="{!otherCertVal}"></apex:inputText>          
     </apex:outputPanel>
      
    </apex:form> 
</apex:page>
 
public with sharing class PageController 
{

    public String otherCertVal { get; set; }
    
    String[] certVals = new String[]{};
    
    public Boolean showField{ get; set; }
    
    public PageController()
    {
        showField = False;
    }
    
    public List<SelectOption> getItems() 
    {        
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Salesforce Admin','Salesforce Admin'));
        options.add(new SelectOption('Salesforce Advance Admin','Salesforce Advance Admin'));
        options.add(new SelectOption('Salesforce Developer','Salesforce Developer'));
        options.add(new SelectOption('Other','Other'));
        return options;
    }
    
    public String[] getcertVals() 
    {
        return certVals; 
    }
    
    public void setcertVals(String[] certVals)
    {
        this.certVals = certVals;
    }
    
    public pageReference othercheck()
    {                
        if(!certVals.isEmpty() && certVals[0].equalsIgnoreCase('Other'))
        {            
            showField = TRUE;            
        }
        else if(certVals.isEmpty())
        {
            showField = False;  
        }
        else
        {
            showField = False;  
        }
        return null;
    }
    
}

Hope this helps.

Regards,
Lakshmi.
This was selected as the best answer
sk kumarsk kumar
thnx lakshmi fr yr quick response...but my requirement is if i select a check box..a blank checkbox will appear next to the checkbox..& when i unclick the checkbox the the textbox will desapear
lakslaks
That's exactly what happens in the above code when you click on the checkbox "Other"
When you check it, a textbox appears, when you uncheck it the textbox goes off.
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
If I got it right, you can do it using javascript, JQuery preferably. It would be something like this:
 
<apex:page standardController="OrdemFabricacao__c">
    <style type="text/css">
        .hidden-text-box { display: none; }
    </style>
    <apex:includeScript value="{!URLFOR($Resource.JQuery1_11_1)}" />
    <apex:pageblock>
        <apex:form>
            <apex:pageblockSection columns="2">     
                <apex:outputPanel>
                    <apex:inputCheckbox value="{!OrdemFabricacao__c.Checkbox1__c}" styleClass="chk-text" />
                    <apex:inputField value="{!OrdemFabricacao__c.TextBox1__c}" styleClass="hidden-text-box" />
                </apex:outputPanel>
                <apex:outputPanel>
                    <apex:inputCheckbox value="{!OrdemFabricacao__c.Checkbox2__c}" styleClass="chk-text" />
                    <apex:inputField value="{!OrdemFabricacao__c.TextBox2__c}" styleClass="hidden-text-box" />
                </apex:outputPanel>         
            </apex:pageblockSection>
        </apex:form> 
    </apex:pageblock>
    <script type="text/javascript">
        j$ = jQuery.noConflict();
        j$(function() {
            j$(".chk-text").click(function(){
                j$(this).next().toggle();
            });
        });
    </script>
</apex:page>



Be aware that you also can do it using purely Apex, is up to you choose an option.

Kind regards.
 
sk kumarsk kumar

Thnx   Zuinglio Lopes Ribeiro Júnior & Laks for yr quick response...:)