You can trim that down even more:

    function selectAllCheckboxes(select) {
        var checked = $('checkAllRemove').checked;
        $('newspaperForm').getInputs('checkbox').each(function(el) {
            el.checked = checked;
        });
    }

Also, I realize this probably isn't your production code, but you should
always wrap the labels for checkboxes and radio buttons in a <label>
element. This lets you click the text instead of the tiny box...

<input t:type="checkbox" t:id="yahoo_check" value="subscribeYahoo"/><label
for="yahoo_check">Yahoo</label>
<input t:type="checkbox" t:id="google_check" value="subscribeGoogle"/><label
for="google_check">Google</label>
<input type="checkbox" id="checkAllRemove"
onClick="selectAllCheckboxes();"/><label
for="checkAllRemove">Check All</label>

Josh


On Tue, Jan 18, 2011 at 11:54 PM, dwi ardi irawan
<penyihirke...@gmail.com>wrote:

> I agree ....
> this is my solution. thnx to josh canfield who give me the idea.
>
> Instead of using document.getElementsByTagName("INPUT") then check whether
> is checkbox or not, I prefer to use this method. the same idea as josh
> canfield but I try to get the form element as the root of iteration, not
> the
> input. it's to avoid if there is more than one form in one page.
>
> IHMO(cos I doesn't have enough experiance to make an opinion which one is
> better). what I mean with a simple solution is we try to do this in client
> side. and we don't have to use others component.
>
> <script type="text/javascript" language="JavaScript">
>
>         function selectAllCheckboxes(select){
>
>             <!-- //
>             var form = document.getElementById("newspaperForm");
>             var checkAll = document.getElementById("checkAllRemove");
>             if(checkAll.checked){
>                 for (var i=0;i<form.length;i++)
>                 {
>                     if (form.elements[i].type == "checkbox") {
>                         form.elements[i].checked = true;
>                     }
>                 }
>             }else{
>                 for (var i=0;i<form.length;i++)
>                 {
>                     if (form.elements[i].type == "checkbox") {
>                         form.elements[i].checked = false;
>                     }
>                 }
>             }
>             // -->
>         }
>  </script>
>
> <form t:type="form" t:id="newspaperForm">
>    <input t:type="checkbox" t:value="subscribeYahoo"/>Yahoo
>    <input t:type="checkbox" t:value="subscribeGoogle"/>Google
>    <input type="checkbox" id="checkAllRemove"
> onClick="selectAllCheckboxes();"/>Check All
>     <input type="submit" value="Submit"/><br/>
>    Result : <b>${value}</b>
> </form>
>
>  I am sorry, I am not very fluently in english. ^^,
>
> regards,
>
> dwi ardi irawan
>
> On Wed, Jan 19, 2011 at 12:16 PM, Taha Hafeez <tawus.tapes...@gmail.com
> >wrote:
>
> > Yes, this is an option as are others and these can be used AFAIK. The
> > thread
> > there shows a way to use it even if javascript is disabled
> >
> > regards
> > Taha
> >
> --
>

Reply via email to