3

For each element returned by

{! followers }

one checkbox is created. I have a submit button, and 'on Submit' I want to record which checkboxes are and are not checked.

<apex:repeat value="{! followers }" var="follower">
    $('#attendees').append(
        $('<div>').css('display','inline').append(
            $('<input>', {type:"checkbox"}).addClass('myCheckBox').attr('id', '{! follower.subscriberId }')
        ).append(
            $('<label>').text('{! follower.Subscriber.Name }')
        )
    );  
</apex:repeat>

How would I pass the values from these check boxes to the submit button? I just want to alert() or console.log() them once they reach the submit button.

Something like this maybe?

if ($('.myCheckBox').is(':checked')){
    alert($('.myCheckBox').attr(?))
};

Or this?

if ($('#attendees input').is(':checked')){
    alert($('#attendees input').attr('???'))
};
5

Found a solution:

var cbValues = $(".myCheckBox").map(function() {
    return this.checked;
}).get();

alert(cbValues);
  • mark your solution as "solved" – Scott Pelak Oct 17 '13 at 17:30
  • It takes 2 days before you can mark your own answer as correct. – Daft Jun 11 '14 at 9:02

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