Wednesday, 14 August 2013

Getting all checkboxes that have been checked and then looping through them

Getting all checkboxes that have been checked and then looping through them

Ok, I have a situation where I have a page which has checkboxes on it next
to items with input text fields.
I have a button at the top with the same fields of which the user can use
to apply the settings to all the fields in the page that have been
selected with their respective checkbox.
I'm trying to work out how to get all the checkboxes in the page that have
been checked an then loop through them so I can possibly grab the ID for
that row and then update the respective items, but I'm not 100% sure how
to do this.
Each of the checkboxes on the page have the same class name, so I thought
something like this would work..
var selected = $('input:checked', '.discount_select');
But it doesn't appear to work.
Here is a example checkbox and it's corresponding text box..
<input type="text" size="4" name="discount[101129]">
<input type="checkbox" value="1" class="discount_select"
name="select[101129]">
So basically I wanna loop through the found selectec checkboxes, hopefully
be able to pull out the id 101129 somehow and then be able to update the
textbox with that same id.
JsFiddle: http://jsfiddle.net/79udU/

No comments:

Post a Comment