View Full Version : jquery retrieve all checkboxes in a form value

08-10-2010, 04:43 PM
I have a filter form which has multiple checkbox groupings on it, such as gender which has 3 possible values, status which has 5 possible values, city which has 3 possible areas. I need to get the name of the checkbox and the value for each group that is checked. The code below is what I've been asked to get into. I did the advfil line.

The item is the name of each checkbox, say gender, city, status. I just need the value from each of those.

function applyAdvSearch(){
trace("applyAdvSearch entered");
//var sg = jQuery("#reportmainsearch").filterGrid("#reportgrid",{gridModel: true, gridNames:false})[0];
var checkedArr = getArrCheckedItems();
$("#reportmain input:text").each(function(){if($(this).css("visibility")=="hidden"){$(this).attr("value","");}});
if(typeof checkedArr == "object"){
for(var item in checkedArr){
if(typeof checkedArr[item] == "object"){
tempstr = checkedArr[item].join(",");
trace("#reportmain input:[name="+item+"]:text");
// stack url to send over filters
advfil=advfil + "&" + item + "=" + $('#advsearchbox.' + item + ').val();
//trace($("#reportmain input:[name="+item+"]:text").attr("name"));
$("#reportmain input:[name="+item+"]:text").attr("value",tempstr);

08-10-2010, 05:19 PM
Got it:

advfil=advfil + "&" + item + "=" + $("#advsearchbox input:checkbox[name="+item+"]:checked").val();

What a great day to be alive!