Reputation: 627
I am trying to read checkbox values using jquery .map like below:
var cars=$("#carsid input[name=car]:checked").map(function(){
return $(this).val();)).get().join(',');
But above code throwing length is null or not an object.I dont understand,what is the issue here.Can anyone give hints?
Regards,
Raj
Upvotes: 0
Views: 581
Reputation: 15231
Your script contains some syntax errors. Additionally, you want to do the .get().join(',')
on the whole object when it is returned, not on each individual element. Try changing it to this:
var cars = $("#carsid input[name=car]:checked").map(function() {
return $(this).val();
}).get().join(',');
My change is to remove the extra ;))
after $(this).val()
. Then I moved .get().join(',')
to operate on the returned jQuery object, rather than each element.
Here is a demo showing this in action ->
Upvotes: 1
Reputation: 17314
you're selecting on carsid
, which isn't a tag. You probably want a #
before it if it's an ID, or a .
if it's a class.
Upvotes: 0