File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Getting Values Of a Group of Check Boxes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Getting Values Of a Group of Check Boxes" Watch "Getting Values Of a Group of Check Boxes" New topic
Author

Getting Values Of a Group of Check Boxes

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
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: 61106
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

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: 1439
    
    1
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: 61106
    
  66

 
wood burning stoves
 
subject: Getting Values Of a Group of Check Boxes