nionta's avatar

checkbox click event

here is my Jquery:

 $(".subjectCheckbox").on('change',function() {
            $("input[name='subject_multi_id[]']").each(function() {
                if(this.checked) {
                        console.log($(this).val());
                }
            });
         });

and this is my checkbox on which I am working:

$('#subject_value').append(
                                    '<tr><td>' + '<input class="subjectCheckbox" type="checkbox" id="subject_multi_id[]" name="subject_multi_id[]" value="' + element.subject_id + '"  >' +
                                    element.subject_name + '</td></tr>');

once I checked a checkbox, i want to show the value on the console, again when I check another checkbox, that will again show the value. but my jquery is not working. any one can help me here?

0 likes
1 reply
MortenS's avatar

Try replacing "input[name='subject_multi_id[]']"with "input[name^='subject_multi_id']"

Which means 'all inputs with name attributes that start with...'.

Probably unrelated, but all your inputs will end up with identical id attributes. AFAIK the square bracket syntax is only for name attributes.

1 like

Please or to participate in this conversation.