pnirwan pnirwan - 7 months ago 13
Javascript Question

Extracting checkboxes values and sending it without form post

I have been trying to exract values from a checkbox group, but somehow it is not working. Here is what I am doing:

From a loop generating checkboxes

<input class="group1" type="checkbox" name="catCheck" value="VALUE_I">


There is a button inside a form. On clicking that button, a javascript function is called where I want to extract these values. I have tried following methods:

(1).

alert($("input[name=catCheck]:checked").map(
function () {return this.value;}).get().join(","));


(2).

var matches = [];
$(".group1:checked").each(function() {
matches.push(this.value);
});


Please let me know what am I missing.

Thanks in advance

Answer

Problem was with my jQuery plugin. I work on a large project and somehow there is a conflict.

So in this particular page following code is not working

var matches = [];
$(".group1:checked").each(function() {
    matches.push(this.value);
}); 

When I replaced $ with jQuery, it worked!

   var matches = [];
   jQuery(".group1:checked").each(function() {
        matches.push(this.value);
    }); 

This link has explained it in detail: Difference between jquery and $

But can anyone explain how to locate root of this conflict?