File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Values Of a Group of Check Boxes

 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic