javascript - jQuery 1.9 checkbox count -
i have old jquery code 1.6 works i'm redoing website , upgraded 1.9.1 jquery , old code not work.
$("input[type=checkbox][name=compare[]]").click(function() { var bol = $("input[type=checkbox][name=compare[]]:checked").length >= 5; $("input[type=checkbox][name=compare[]]").not(":checked").attr("disabled",bol); $(this).closest("tr").toggleclass("marked", this.checked); });
i have table rows single checkbox value of row, if checked pushes row id array can work else it. allows 5 checkboxs active @ once , disables rest can't checked (yes know these can done via dom it's checked in php before processing). apply class marked darker bg make easier read.
i receive following error in javascript console in chrome on load
uncaught error: syntax error, unrecognized expression: input[type=checkbox][name=compare[]]
at time code more of hack job , surprised self worked (lol).
the following code select checked checkboxs , put value array json' off via ajax.
$("input[type=checkbox][name=compare[]]:checked").each(function() { data['id[]'].push($(this).val()); });
i've started rewrite hit problem when trying give each checkbox it's own unique identifier, while before jquery self.
.compare_check class of checkbox
$('.compare_check').click(function() { if (!$(this).is(':checked')) { // work on
any appreciated.
wrap value attribute want check in double quotes, you'd have:
$('input[type=checkbox][name="compare[]"]')
rather than
$("input[type=checkbox][name=compare[]]")
alternatively can use \\
escape [
, ]
in attribute name:
$("input[type=checkbox][name=compare\\[\\]]")
you should using .prop()
, rather .attr()
, set elements disabled.
Comments
Post a Comment