3

I'm trying to limit the number of checkboxes that can be checked within a form, but am getting the following error:

Uncaught Error: Syntax error, unrecognized expression: input:checkbox[name=ninja_forms_field_57[terms]]

Here is the Javascript that I'm using:

// Main Category
var $checkboxes_to_limit2 = $("#taxonomy_47").find("input:checkbox[name=ninja_forms_field_47[terms]]");
$checkboxes_to_limit2.live("change", function() {
    if($checkboxes_to_limit2.filter(":checked").length >= 3) {
    $checkboxes_to_limit2.not(":checked").attr("disabled","disabled");
    }
    else {
        $checkboxes_to_limit2.removeAttr("disabled");
    }
});

2 Answers 2

8

You need to treat the name attribute as a string, so

input:checkbox[name=ninja_forms_field_47[terms]]

should be

input:checkbox[name='ninja_forms_field_47[terms]']
Sign up to request clarification or add additional context in comments.

Comments

0

You need some additional single quotes:

var $checkboxes_to_limit2 =
  $("#taxonomy_47").find("input:checkbox[name='ninja_forms_field_47[terms]']")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.