Getting list of Checked Checkboxes in a Div
Hi,
I would like to get a list of the checked CheckBoxes in the div below, when the button is clicked.
- <div id="ScrollCB" style="height:150;width:200px;overflow:auto">
- <input type="checkbox" id="scb1" name="scb1" value="scb1">Milk<br>
- <input type="checkbox" id="scb2" name="scb2" value="scb2">Butter<<br>
- <input type="checkbox" id="scb3" name="scb3" value="scb3">Cheese<br>
- </div>
- <input type="button" value="Get Values of Selected" onClick="getSourceValues();">
I am trying the following function/method:
function getSourceValues() {
$("#ScrollCB").find(":checkbox").each(function(i) {
//Attempted some if statements here
alert(this.id + " = " + i);
});
};
I tried the various ways of getting the checked using
- if(this.attr('checked'))
and I have not been successful.
Thanks a lot guys,
O.O.