Pergunta

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('???'))
            };
Foi útil?

Solução

You can get a full list of values inside an array using the .map() function:

var cbValues = $(".myCheckBox").map(function() {
    return this.checked;
}).get();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top