how to access all checkboxes that have a name that begins with "abc"?

29 views
Skip to first unread message

Dennis Haupt

unread,
Jul 15, 2011, 11:07:56 AM7/15/11
to google-we...@googlegroups.com
hi community, 

i'm in a gwt module that is part of a bigger page, and i need to know which checkboxes that are on this page are selected. i know what the names of these boxes are, but i don't know how many there are.

how can i a) get them all and b) find out which ones are checked from inside my gwt entry point?

dreamer

unread,
Jul 15, 2011, 11:59:41 AM7/15/11
to Google Web Toolkit
One way is build your own collection (ArrayList) and make accessible,
with setter and getter ,just like in any java class.

Aidan O'Kelly

unread,
Jul 15, 2011, 12:29:01 PM7/15/11
to google-we...@googlegroups.com
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NodeList;
.
.
.
NodeList<Element> elementList = Document.get().getElementsByTagName("input");


This will give you a list of all HTML 'input' elements on the page,
you can loop through them and check the type/id/value of the element
for the ones you are interested in.


On Fri, Jul 15, 2011 at 4:07 PM, Dennis Haupt <d.ha...@googlemail.com> wrote:
> hi community, /v

> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-tool...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>

Jens

unread,
Jul 15, 2011, 12:33:57 PM7/15/11
to google-we...@googlegroups.com
I guess you have to use something like:

for(Element e : Document.get().getElementsByTagName("input")) {
 if(e instanceof InputElement) {
   InputElement ie = (InputElement) e;
   if("checkbox".equals(ie.getType()) && ie.getName().startsWith("abc") && (ie.isChecked() || ie.isDefaultChecked())) {
      //do your stuff here
   }
 }
}

I haven't tried it but it should check every input element if its a checkbox, its name starts with "abc" and if its checked.


Jeff Chimene

unread,
Jul 15, 2011, 1:41:08 PM7/15/11
to google-we...@googlegroups.com

gQuery will be a good tool choice

Dennis Haupt

unread,
Jul 16, 2011, 2:12:22 AM7/16/11
to google-we...@googlegroups.com
and how do i get them in the first place? i don't create them, they
already exist on the page

Dennis Haupt

unread,
Jul 16, 2011, 2:12:49 AM7/16/11
to google-we...@googlegroups.com
thx


--
Mit freundlichen Gr��en,

Dennis Haupt
Plettstrasse 73
81735 M�nchen
Handy 0176/80130332

Reply all
Reply to author
Forward
0 new messages