+ Start a Discussion

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

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.
Here is the code. You have to do something like this:

-------------------------------------------------------VF Page----------------------------------
<apex:page controller="checkController">
        <apex:actionFunction name="insertVal" action="{!insertValuetoField}" reRender="pageBlockTableId"/>
            <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:commandButton value="Save" action="{!saveCon}"/>

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){
        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.