Reputation:
I want to show the multiple value of checkbox in a div or textbox.
function countChecked() {
var n = $("input:checked").val();
$("div").text(n + (n === 1 ? " is" : " are") + " checked!");
}
countChecked();
$(":checkbox").click(countChecked);
Upvotes: 3
Views: 1022
Reputation:
function countChecked() {
var n= "";
$("input[type=checkbox]:checked").each(function(){
n += $(this).val() + " ";
});
$("#change").text(n);
}
countChecked();
$(":checkbox").click(countChecked);
Upvotes: 0
Reputation: 144659
try this:
function countChecked() {
var n = 0;
$(":checkbox:checked").each(function(){
n += parseInt(this.value, 10)
})
$("div").text(n + (n === 1 ? " is" : " are") + " checked!");
}
Upvotes: 2