0

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

2 Answers 2

1

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 ->

Sign up to request clarification or add additional context in comments.

1 Comment

it doesn't make any difference.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.