admin管理员组文章数量:1435859
I need to get the values of all checkboxes that are currently checked using jquery, I suppose I would put it all in an array, but I am having trouble doing that. Would anyone be able to point me in the write direction.
This is what I am using so far. I am trying to send all of the values that are currently checked to a div I have.
function cityPopulate() {
var arr44 = new Array();
var cityNames22 = $("input[name=city_select[]]:checked").each(function(){arr44.push(this.value);});
$("#city_pop").append(cityNames22.val());
}
When I try the code above, it just gives me the value of the first checkbox I check only. Not all of the rest.
I need to get the values of all checkboxes that are currently checked using jquery, I suppose I would put it all in an array, but I am having trouble doing that. Would anyone be able to point me in the write direction.
This is what I am using so far. I am trying to send all of the values that are currently checked to a div I have.
function cityPopulate() {
var arr44 = new Array();
var cityNames22 = $("input[name=city_select[]]:checked").each(function(){arr44.push(this.value);});
$("#city_pop").append(cityNames22.val());
}
When I try the code above, it just gives me the value of the first checkbox I check only. Not all of the rest.
Share
Improve this question
edited Mar 13, 2012 at 21:17
Bill paxton
asked Mar 13, 2012 at 21:11
Bill paxtonBill paxton
952 gold badges3 silver badges9 bronze badges
2
- Can you post the code you have so far. – Rory McCrossan Commented Mar 13, 2012 at 21:12
- Possible duplicated question: stackoverflow./questions/786142/… – lmcanavals Commented Mar 13, 2012 at 21:13
2 Answers
Reset to default 3Without seeing the code you have I'm guessing at your exact schema, but using map()
on your checkboxes with the class you specify to create an array should work, try this:
var checkboxValues = $('.myCheckbox:checked').map(function() {
return $(this).val();
}).get();
checkboxValues
would then contain an array with all the values of the checked checkboxes.
Depending on the class you have assigned to your checkboxes, it will look something like this:
var values = [];
$('.checkboxclass').each(function(){
var $this = $(this);
if ($this.is(':checked')) {
values.push($this.val());
}
});
本文标签: javascriptHow to get the values of multiple checkboxes with the same class with jqueryStack Overflow
版权声明:本文标题:javascript - How to get the values of multiple checkboxes with the same class with jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745414167a2657604.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论