Lets say I have a table of records and a button to update multiple records in the table on a visualforce page. I want to check the values of each record in the repeat block, and grab each records Id and checked box value and put them in a map. I do not know how to look at each element in the repeat block when I call my function. I am

<script type="text/javascript"> j$ = jQuery.noConflict(); j$(document).ready(function() { function sendIds() { var peopleIds = {}; //pseudo code for all People p: peopleIds[p.Id] = p.isChecked; }); ); </script> <button onclick="sendIds();">Apply</button> <apex:repeat value="{!Peoples}" var="People"> <tr> <td><apex:outputLink value="/{!People.ID}" id="theLink">{!People.Name}</apex:outputLink></td> <td>{!People.Position_Description__c}</td> <td>{!People.Work_Email__c}</td> <td><apex:inputCheckbox value="{!People.CheckBox__c}" ></apex:inputCheckbox> </td> </tr> </apex:repeat>

I saw some people posting on using the styleClass so then jquery and loop through and find each element with that class, but how would I get the record id then? Thanks to all in advanced!!!!


You can bind the record Id to the checkbox id (or other HTML5 pass-through attribute).

This component supports HTML pass-through attributes using the "html-" prefix. Pass-through attributes are attached to the generated tag.

So your checkbox will look something like this:

<apex:inputCheckbox value="{!People.CheckBox__c}" styleClass="myCoolCheckbox" id="{!People.Id}" ></apex:inputCheckbox>


<apex:inputCheckbox value="{!People.CheckBox__c}" styleClass="myCoolCheckbox" html-sf-id="{!People.Id}" ></apex:inputCheckbox>

Then in your Javascript code you can look through the checkboxes with the "myCoolCheckbox" style class applied, check which ones are selected and concatenate the Id's:

var selectedPeopleIds = [];
$('.myCoolCheckbox').each(function(i, obj) {
    if (obj.checked)
        selectedPeopleIds.push(obj.id); // or "sf-id" attribute if it was the other scenario
  • Thank you very much. One more question if you don't mind. – jaaaaaahhhhh Nov 16 '15 at 4:43
  • Do you use the connection.js library, or use .ajax in jquery? – jaaaaaahhhhh Nov 16 '15 at 4:44
  • I always tend to keep it simple and small, so unless you're building some really complex stuff, just use standard ajax. Avoid loading libraries in order to save a couple of lines of code ;) – Boris Bachovski Nov 16 '15 at 4:52
  • Please respect the site's rules and post that as a different question. If my answer solved your original problem then accept it so that we close this thread. – Boris Bachovski Nov 16 '15 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.