goog.ui.Checkbox only with span?

52 views
Skip to first unread message

moose

unread,
Jan 3, 2011, 6:44:26 AM1/3/11
to Closure Library Discuss
Hi,

I am trying to get a root tri-state-checkbox work with some normal
checkboxes. Its always only one root checkbox, but the number of leaf-
checkboxes can vary:

<div><span id="root"></span> Select/Deselect All</div>
<div id="AllNormalCheckboxes">
<label for="c1">Label 1</label><input type="checkbox" id="c1"/>
<label for="c2">Label 2</label><input type="checkbox" id="c2"/>
<label for="c3">Label 3</label><input type="checkbox" id="c3"/>
...
<label for="c12">Label 12</label><input type="checkbox" id="c12"/>
</div>

My script works fine if I use span-tags instead of input-tags, but I
can't be sure if JavaScript is enabled. So I have to use input-tags.

I could use goog.dom.getElement('c1').checked; and
goog.dom.getElement('c1').checked=true instead of getChecked() and
setChecked(). Is this the best way to do so?

Thanks in advance,
Martin

Garry Boyer

unread,
Jan 4, 2011, 1:38:45 PM1/4/11
to closure-lib...@googlegroups.com
On Mon, Jan 3, 2011 at 3:44 AM, moose <themoo...@googlemail.com> wrote:
Hi,

I am trying to get a root tri-state-checkbox work with some normal
checkboxes. Its always only one root checkbox, but the number of leaf-
checkboxes can vary:

<div><span id="root"></span> Select/Deselect All</div>
<div id="AllNormalCheckboxes">
   <label for="c1">Label 1</label><input type="checkbox" id="c1"/>
   <label for="c2">Label 2</label><input type="checkbox" id="c2"/>
   <label for="c3">Label 3</label><input type="checkbox" id="c3"/>
   ...
   <label for="c12">Label 12</label><input type="checkbox" id="c12"/>
</div>

My script works fine if I use span-tags instead of input-tags, but I
can't be sure if JavaScript is enabled. So I have to use input-tags.

How certain are you that your target market requires a Javascript-free version?  If it's a hard requirement, you're simply not going to get a working tri-state checkbox.
Reply all
Reply to author
Forward
0 new messages