Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag for United States of America

asked on

Checkboxes

Hi,

I need to get the value of these checkboxes in a list.  

My checkboxes: 

<input type="checkbox" class="ChkCatg" name="Chk1" id="Chk1" value="1"  />
<input type="checkbox" class="ChkCatg" name="Chk2" id="Chk2" value="2" />
<input type="checkbox" class="ChkCatg" name="Chk3" id="Chk3" value="3" />
<input type="checkbox" class="ChkCatg" name="Chk4" id="Chk4" value="4" />

I need jquery to loop thru my checked checkboxes and have the value as a list.

I just want the checkboxes that are checked. 

so the output will look like this: 

var Catg = (1,3,4);

 function AdHocRpt()
  {
//loop thru the checked checkboxes 
//get the value as a list 

var Catg = (1,3,4);

}

Open in new window



Thank you
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lulu50

ASKER

Gary,


Thank you for the example:

just one thing, that I need to fix.


//how can I say to get all the checkbox that have only ChkCatg class?.
//because I have some other checkboxes on the form. 

 function AdHocRpt()
  {
	 ValidateRpt();
	  
	  var checkboxes = $('.ChkCatg input:checkbox:checked').map(function() {
    	return this.value;
		}).get();

	  alert(checkboxes);
  }

Open in new window

Avatar of lulu50

ASKER

Gary,

I fixed it!!!!


Thank you

 

var checkboxes = $('input:checkbox.ChkCatg:checked').map(function() {
    	return this.value;
		}).get();

Open in new window

Avatar of lulu50

ASKER

Thank you
I was away, you only need the following but what you came up with is good

var checkboxes = $(.ChkCatg:checked').map(function() {
    	return this.value;
		}).get();

Open in new window