| Author |
Getting Values Of a Group of Check Boxes
|
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1260
|
|
I have a jsp in which I use jstl for each loop to create a dynamic group of checkbox tags. Each tag is given an id of a prefix prefdw and then the status.count of the loop. A value is also assigned to each tag from the items attribute.
I need javascript that can read these values with out having to hard code the tag ids.value. How can I iterate over a set of tags based on a partial id parameter?
How can the js know how many checkbox tags there are with partial name of 'prefdw'?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56521
|
|
Ditch the ids. I assume that the checkboxes are part of a checkbox group, and hence have the same name? Use the name to collect the checkboxes, then iterate over them to get the values.
The selector $('[name="group"]') will collect the checkboxes (where "group" is the name of the checkbox group).
Then $.each() or $.map() can be used to collect the values.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56521
|
|
P.S. If the checkboxes are not part of the same checkbox group, assign a class to organize them.
id values are overused, and should never be used to identify a group of elements.
P.P.S. And the above assumes you are using jQuery, of course.
|
 |
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1260
|
|
Bear Bibeault wrote:P.S. If the checkboxes are not part of the same checkbox group, assign a class to organize them.
id values are overused, and should never be used to identify a group of elements.
P.P.S. And the above assumes you are using jQuery, of course.
Thanks it works great
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56521
|
|
|
 |
 |
|
|
subject: Getting Values Of a Group of Check Boxes
|
|
|