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
lakshman.mattilakshman.matti 

Visualforce page with check box

Hi Everyone,

i have a requirement.
i have a page, which displays list of records.each record contains check box and inputbox.
when i select a check box,we have to populate 1 as defualt number in input box after that user can edit with different number.(default should be 1 for selected check box i.e record).
i have a button below the button.when i click on this button i need add them into  object.

i hope i'm clear with question.

Thanks in Advance
Lakshman

 
Sagar PareekSagar Pareek
You need to used wrapper class in you code. 
Here is the great article from where you can learn how to achieve this functionality.
https://developer.salesforce.com/page/Wrapper_Class
NK@BITNK@BIT
Here is the code. You have to do something like this:

-------------------------------------------------------VF Page----------------------------------
<apex:page controller="checkController">
    <apex:form>
        <apex:actionFunction name="insertVal" action="{!insertValuetoField}" reRender="pageBlockTableId"/>
        <apex:pageBlock>
            <apex:pageBlockTable value="{!contactRecord}" var="con" id="pageBlockTableId">
                <apex:column><apex:inputCheckbox value="{!con.check}" id="checkBoxid" onchange="insertVal();"/></apex:column>
                <apex:column value="{!con.con.Name}"/>
                <apex:column headerValue="Input Value"><apex:inputField value="{!con.con.Rec__c}" id="inputfieldId"/> </apex:column>
            </apex:pageBlockTable>
            <apex:pageBlockButtons>
                <apex:commandButton value="Save" action="{!saveCon}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

----------------------------Controller-----------------------------------------------
public class checkController{
    public List<wrapperClass> contactRecord{get; set;}
    public checkController(){
        contactRecord = new List<wrapperClass>();
        for(Contact cont : [select Name, Rec__c, CreatedDate from Contact Limit 10]){
            contactRecord.add(new wrapperClass(cont));
        }
    }
    
    public void insertValuetoField(){
        for(wrapperClass w : contactRecord){
            if(w.check == true && w.con.Rec__c == null){
                w.con.Rec__c = 1;
            }
        }
    }
    
    public void saveCon(){
        List<Contact> contactToUpdate = new List<Contact>();
        for(wrapperClass w : contactRecord){
            if(w.check == true && w.con.Rec__c != null){
                contactToUpdate.add(w.con);
            }
        }
        if(contactToUpdate.size() > 0)
            update contactToUpdate;
    }
    
    public class wrapperClass{
        public Contact con{get;set;}
        public boolean check{get; set;}
        public wrapperClass(Contact c){
            con = c;
            check = false;
        }
    }
  
}

In this Rec__c is the field that I am updating on the contact record.