Reputation: 13
I try to make a form with jquery 1.11.1, but the checkboxes do not work! which is the syntax error?
$(this + "input[name=''] :checked").each(function() {
totalSum += parseInt($(this).val());
});
Upvotes: 1
Views: 4487
Reputation: 490303
Just to be different...
var totalSum = $(this)
.find("input[name='']:checked")
.map(function() { return parseInt(this.value, 10); })
.get()
.reduce(function(total, value) { return total + value; }, 0);
Upvotes: 0
Reputation: 74076
You probably want to use something like this:
$( this ).find( "input[name='']:checked" ).each(function() {
totalSum += parseInt($(this).val());
});
Using find()
you can search for elements, which are descendants of a given element.
Anyway, are you sure you want to search for <input>
elements, which have a name
attribute set to an empty string? Because that is, what you are currently selecting.
Upvotes: 2