Select all checkboxes?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Select all checkboxes?

Luc Pestille

Hi all,

I’ve only just found out about jQuery and started using it on a couple of projects – it’s very easy to use, but I can’t seem to do the following – I can’t find what I want in any demos or the docs;

 

Given a form with multiple checkboxes all named the same, how do I create the jQuery code to enable another checkbox (named differently) to select all of the others? I’ve only really dealt with $(form#Name).submit{ function(){} } – is there an alternative like .click or .select ?

 

Regards,

Luc Pestille


_______________________________________________
jQuery mailing list
[hidden email]
http://jquery.com/discuss/
Reply | Threaded
Open this post in threaded view
|

Re: Select all checkboxes?

malsup
Hi Luc,

Try something like this:

$("[@name='mainName']").change(function() {
    var x = this.checked;
    $("[@name='sameName']").each(function() {
        this.checked = x;
    });
});

_______________________________________________
jQuery mailing list
[hidden email]
http://jquery.com/discuss/
Reply | Threaded
Open this post in threaded view
|

Re: Select all checkboxes?

Choan Gálvez
On 6/7/06, Mike Alsup <[hidden email]> wrote:

> Hi Luc,
>
> Try something like this:
>
> $("[@name='mainName']").change(function() {
>     var x = this.checked;
>     $("[@name='sameName']").each(function() {
>         this.checked = x;
>     });
> });

Hi Luc, Mike, everybody,

Using the onchange event in checkboxes in IE can lead to problems
(I've found situations where the onchange doesn't fire till the
checkbox loses focus).

I'd recommend using onclick instead.

So

   $([@name=mainName]).click(f);

--
Choan
<http://choangalvez.nom.es/>

_______________________________________________
jQuery mailing list
[hidden email]
http://jquery.com/discuss/