Multiple IDs in one code

I have this code for limiting checkboxes in a form and I want to know if it's possible for me to utilize it with more than one ID, something like 10 options limit between those two forms(The IDs are iphorm_1_10 and iphorm_1_12)

Thanks!

<script>
jQuery(document).ready(function ($) {
    var $checkboxes = $('.iphorm_1_10');

    $checkboxes.click(function () {
        var checked = 0;
        $checkboxes.each(function () {
            if ($(this).is(':checked')) {
                checked++;
            }
        });

        if (checked > 10) {
            alert('You can only select 10 options')
            $(this).prop('checked', false);
            $.uniform.update();
            return false;
        }
    });
});

Upvotes: 0

Views: 44

Answers (1)

Heady
Heady

Reputation: 985

I am confused. $('.iphorm_1_10'); refers to CLASS .iphorm_1_10 and not ID, am i wrong? If you use classes, just give your forms the same class. If you want to use ID's, repeat your .each for every ID you got.

Upvotes: 1

Related Questions