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
Malli GMalli G 

select the inputcheckbox get the index or row id

hai all 
on vfpage i have 4 inputcheckbox, if i selected checkbox 1 add to integer and then display the selected seat is 1 and if i selected checkbox 3 add to integer and then display the selected seat is 3  Iwant display the statically or dynamically
i wrote the code
it will count the noof seats
public class adds {
    public integer count{set;get;}
    public boolean book1{set;get;}
     public boolean book2{set;get;}
     public boolean book3{set;get;}
     public boolean book4{set;get;}
    public boolean book5{set;get;}
    public integer index{set;get;}
    public adds(){
      
        count=0;
    }
    public  void add1(){
        if(book1==true){
            count=count+1;
          index=1;
        }else if(book2==true){
            count=count+1;
            index=2;
        }else if(book3==true){
            count=count+1;
           
        }else if(book4==true){
            count=count+1;
        }else if(book5==true){
            count=count+1;
        }
    }
}
vfpage
<apex:page controller="adds" >
    <apex:form >
     <apex:pageblock id="one">
         <apex:inputCheckbox value="{!book1}">
             <apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;
         <apex:inputCheckbox value="{!book2}"><apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;
         <apex:inputCheckbox value="{!book3}"><apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;&nbsp;
          <apex:inputCheckbox value="{!book4}"><apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;
          <apex:inputCheckbox value="{!book5}"><apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;
          
         {!count} selected seats{!index}
        </apex:pageblock>
    </apex:form>
</apex:page>

 
Srinivas SSrinivas S
Hi Malli,

Please find the following solution which is tested - 

Controller Class: 
public class SeatBookingContrl {
    public List<Integer> selSeats {get;set;}
    public Integer totSeats {get;set;}
    List<Seat> appliedSeats;
    
    public SeatBookingContrl() {
        totSeats = 0;
    }
    public List<Seat> getSeats() {
        Seat s1 = new Seat();
        s1.seatNum = 1;
        s1.seatName = 'r1';
        Seat s2 = new Seat();
        s2.seatNum = 2;
        s2.seatName = 'r2';
        Seat s3 = new Seat();
        s3.seatNum = 3;
        s3.seatName = 'r3';
        Seat s4 = new Seat();
        s4.seatNum = 4;
        s4.seatName = 'r4';
        appliedSeats = new List<Seat>{s1,s2,s3,s4};
        return appliedSeats;
    }
    
    public void submit() {
        selSeats = new List<Integer>();
        for(Seat appSeat : appliedSeats) {
            if(appSeat.isSelected) {
                totSeats++;
                selSeats.add(appSeat.seatNum);
            }
        }
    }

    //Wrapper/Inner class to hold the seat information
    public class Seat {
        public Integer seatNum {get;set;}
        public String seatName {get;set;}
        public Boolean isSelected {get;set;}
        public Seat() {
            IsSelected = false;
        }
    }
}

Apex Page: 
<apex:page controller="SeatBookingContrl">
    <apex:form id="frm">
        <apex:pageBlock title="Book a Seat">
            <apex:pageBlockTable value="{!seats}" var="seat">
                <apex:column headerValue="Action">
                    <apex:inputCheckbox value="{!seat.isSelected}"/>
                </apex:column>
                <apex:column value="{!seat.seatName}" headerValue="Seat Name"/>
            </apex:pageBlockTable>
            <apex:outputPanel id="infoPanel">
                <apex:outputText>Number of seats selected: {!totSeats}</apex:outputText><br/>
                <apex:outputText>Selected seat numbers: <apex:repeat value="{!selSeats}" var="selSeat">{!selSeat};</apex:repeat></apex:outputText>
            </apex:outputPanel>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Submit" action="{!submit}" reRender="infoPanel"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.