0

I have a list - house and I am displaying it on a table using apex:repeat. In this table, I want a user input checkbox which I have implemented using apex:inputCheckbox.

<td><apex:inputCheckbox id="CeilingHeightCostCheckbox" value="{!house.CeilingHeightCostCheck}" selected="true" disabled="{!IF(house.Pckg_Ground_Floor_Ceiling_Height_Cost != 0, false, true)}" onchange="CeilingHeightCostCheckChange"/></td>

I am trying to check the user picked state of this inputCheckbox inside javascript using -

  var CheckboxState = $('[id$=CeilingHeightCostCheckbox]').is(':checked');

This is working fine if I just have 1 row in the list but when there are more than 1 rows, its giving random results. I guess because there are more than 1 checkboxes with id - CeilingHeightCostCheckbox how can I generate unique ids in this scenario or if there is another way to show checkbox and capture its state ? Please help.

1
  • I would look into using a wrapper class for capturing list through checkboxes Dec 2, 2021 at 12:58

1 Answer 1

0

You can write the method as:

function CeilingHeightCostCheckChange(event) {
  if(event.target.checked) {
    // do something here
  }
}

All events that are fired from an element have a target that identifies the element that fired the event, so you don't need to query the element again.

1
  • thanks @sfdcfox ....I captured the checkbox state using above code and passed list Id as an argument to store it on the wrapper and that worked for me. Dec 6, 2021 at 4:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .