Forms "Check All" checkboxes

Discussion in 'HTML' started by Steve, Jan 30, 2004.

  1. Steve

    Steve Guest

    I've got a form with a lot of checkboxes set up in a table. I've found some
    Java that will allow me to Check All / Uncheck All ... but it seems to only
    work within the <td> </td> tags.

    Is there a nonJava way to check all the checkboxes on a page? Or is there a
    Java applet that will ignore the <td> tags and check everything in the
    table?

    Thanks for any help,
    Steve
     
    Steve, Jan 30, 2004
    #1
    1. Advertising

  2. Steve

    Jeff Thies Guest

    > I've got a form with a lot of checkboxes set up in a table. I've found
    some
    > Java


    Should be javascript, not java.

    > that will allow me to Check All / Uncheck All ... but it seems to only
    > work within the <td> </td> tags.
    >
    > Is there a nonJava way to check all the checkboxes on a page?


    Aside from starting with them all checked? No, not really.

    > Or is there a
    > Java applet that will ignore the <td> tags and check everything in the
    > table?


    This is fairly trivial to do in javascript. Ask in comp.lang.javascript
    after you have read their FAQ.

    Jeff
    >
    > Thanks for any help,
    > Steve
    >
    >
     
    Jeff Thies, Jan 30, 2004
    #2
    1. Advertising

  3. Steve

    O Guest

    Steve <> wrote:
    > Is there a nonJava way to check all the checkboxes on a page?


    You can use the selected attribute on eact input tag:

    <input type="checkbox" name="name" value="val" checked="checked" />


    > Or is there a
    > Java applet that will ignore the <td> tags and check everything in the
    > table?


    Are you sure you're using a Java applet or do you mean a Javascript
    function? Java and Javascript are pretty unrelated things.

    If you want a simple Javascript function to select all checkboxes in
    the current form try this in the <head> section of your page:

    <script type="text/javascript">
    function selectAll(x) {
    for(var i=0,l=x.form.length; i<l; i++)
    if(x.form.type == 'checkbox' && x.form.name != 'sAll')
    x.form.checked=x.form.checked?false:true
    }
    </script>



    In your form, just give the name 'sAll' to the checkbox you want to use
    to run the function and use the onclick attribute to call it:

    <form>
    <input type="checkbox" name="sAll" onclick="selectAll(this)" /> (Select all)<br />
    <input type="checkbox" name="a" /> (A)<br />
    <input type="checkbox" name="b" /> (B)<br />
    <input type="checkbox" name="c" /> (C)<br />
    <input type="checkbox" name="d" /> (D)<br />
    <input type="checkbox" name="e" /> (E)
    </form>

    If you use valid markup and it should work, and can be used from multiple
    forms.
     
    O, Jan 30, 2004
    #3
  4. Steve

    O Guest

    Steve <> wrote:
    > Is there a nonJava way to check all the checkboxes on a page?


    You can use the selected attribute on eact input tag:

    <input type="checkbox" name="name" value="val" checked="checked" />



    > Or is there a
    > Java applet that will ignore the <td> tags and check everything in the
    > table?


    Are you sure you're using a Java applet or do you mean a Javascript
    function? Java and Javascript are pretty unrelated things.

    If you want a simple Javascript function to select all checkboxes in
    the current form try this in the <head> section of your page:

    <script type="text/javascript">
    function selectAll(x) {
    for(var i=0,l=x.form.length; i<l; i++)
    if(x.form.type == 'checkbox' && x.form.name != 'sAll')
    x.form.checked=x.form.checked?false:true
    }
    </script>



    In your form, just give the name 'sAll' to the checkbox you want to use
    to run the function and use the onclick attribute to call it:

    <form>
    <input type="checkbox" name="sAll" onclick="selectAll(this)" /> (Select all)<br />
    <input type="checkbox" name="a" /> (A)<br />
    <input type="checkbox" name="b" /> (B)<br />
    <input type="checkbox" name="c" /> (C)<br />
    <input type="checkbox" name="d" /> (D)<br />
    <input type="checkbox" name="e" /> (E)
    </form>

    If you use valid markup and it should work, and can be used from multiple
    forms.
     
    O, Jan 30, 2004
    #4
  5. Steve

    Decaf Guest

    Steve <> wrote:
    > Is there a nonJava way to check all the checkboxes on a page?


    You can use the selected attribute on eact input tag:

    <input type="checkbox" name="name" value="val" checked="checked" />


    > Or is there a
    > Java applet that will ignore the <td> tags and check everything in the
    > table?


    Are you sure you're using a Java applet or do you mean a Javascript
    function? Java and Javascript are pretty unrelated things.

    If you want a simple Javascript function to select all checkboxes in
    the current form try this in SCRIPT tags in the HEAD section of your page:

    function selectAll(x) {
    for(var i=0,l=x.form.length; i<l; i++)
    if(x.form.type == 'checkbox' && x.form.name != 'sAll')
    x.form.checked=x.form.checked?false:true
    }


    In your form, just give the name 'sAll' to the checkbox you want to use
    to 'select all' and use the onclick attribute to call the function:

    <input type="checkbox" name="sAll" onclick="selectAll(this)" /> (Select all)

    If you use valid markup and it should work, and can be used from multiple
    forms.
     
    Decaf, Jan 30, 2004
    #5
  6. Steve

    Decaf Guest

    Steve <> wrote:
    > Is there a nonJava way to check all the checkboxes on a page?


    You can use the selected attribute on eact input tag:

    <input type="checkbox" name="name" value="val" checked="checked" />


    > Or is there a
    > Java applet that will ignore the <td> tags and check everything in the
    > table?


    Are you sure you're using a Java applet or do you mean a Javascript
    function? Java and Javascript are pretty unrelated things.

    If you want a simple Javascript function to select all checkboxes in
    the current form try this in SCRIPT tags in the HEAD section of your page:

    function selectAll(x) {
    for(var i=0,l=x.form.length; i<l; i++)
    if(x.form.type == 'checkbox' && x.form.name != 'sAll')
    x.form.checked=x.form.checked?false:true
    }


    In your form, just give the name 'sAll' to the checkbox you want to use
    to 'select all' and use the onclick attribute to call the function:

    <input type="checkbox" name="sAll" onclick="selectAll(this)" /> (Select all)

    If you use valid markup and it should work, and can be used from multiple
    forms.
     
    Decaf, Jan 30, 2004
    #6
  7. Steve

    Steve Guest

    "O" <> wrote in message news:...

    > If you want a simple Javascript function to select all checkboxes in
    > the current form try this in the <head> section of your page:
    >
    > <script type="text/javascript">
    > function selectAll(x) {
    > for(var i=0,l=x.form.length; i<l; i++)
    > if(x.form.type == 'checkbox' && x.form.name != 'sAll')
    > x.form.checked=x.form.checked?false:true
    > }
    > </script>



    Excellent, this works. Actually it toggles the boxes back and forth ... if
    I mark about 10 things, then hit sellect all, those 10 things become
    "unmarked" and the rest are marked. Not a big deal though.

    I really appreciate your help. My javascript skills are nonexistant.

    Steve
     
    Steve, Jan 30, 2004
    #7
  8. Steve

    Jeff Thies Guest

    "Steve" <> wrote in message
    news:...
    > "O" <> wrote in message news:...
    >
    > > If you want a simple Javascript function to select all checkboxes in
    > > the current form try this in the <head> section of your page:
    > >
    > > <script type="text/javascript">
    > > function selectAll(x) {
    > > for(var i=0,l=x.form.length; i<l; i++)
    > > if(x.form.type == 'checkbox' && x.form.name != 'sAll')
    > > x.form.checked=x.form.checked?false:true
    > > }
    > > </script>

    >
    >
    > Excellent, this works. Actually it toggles the boxes back and forth ...

    if
    > I mark about 10 things, then hit sellect all, those 10 things become
    > "unmarked" and the rest are marked. Not a big deal though.


    Change this:

    x.form.checked=x.form.checked?false:true

    to:

    x.form.checked=true;

    Jeff

    >
    > I really appreciate your help. My javascript skills are nonexistant.
    >
    > Steve
    >
    >
     
    Jeff Thies, Jan 30, 2004
    #8
  9. Steve

    floortje Guest

    "Steve" <> schreef in bericht
    news:...
    > I've got a form with a lot of checkboxes set up in a table. I've found

    some
    > Java that will allow me to Check All / Uncheck All ... but it seems to

    only
    > work within the <td> </td> tags.
    >
    > Is there a nonJava way to check all the checkboxes on a page? Or is there

    a
    > Java applet that will ignore the <td> tags and check everything in the
    > table?
    >


    yep php will do a good job. I dont knwo sh^t bout html by the way so I dont
    know if the syntax is correct but u should get the idea

    This is a verry dirty way to do it but it works great

    Juts place a link to urpage.php?action=checkall and rewrite ur html. The
    advantage: no Javascript

    <?php if ($_GET['action']=="checkall"){$dummy=" checked";}?>

    and each box
    <input type="checkbox" name="name" value="val"<?php echo $dummy; ?>>
    will give
    <input type="checkbox" name="name" value="val" checked>
    or
    <input type="checkbox" name="name" value="val">

    :)
     
    floortje, Jan 30, 2004
    #9
  10. Steve

    Steve Guest

    "Jeff Thies" <> wrote in message
    news:5aBSb.3668$...
    > Change this:
    >
    > x.form.checked=x.form.checked?false:true
    >
    > to:
    > x.form.checked=true;


    Thanks!

    Steve
     
    Steve, Jan 30, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    929
    Mark Rae
    Dec 5, 2006
  2. Edward

    Check all form checkboxes funtion ??

    Edward, Dec 11, 2003, in forum: Javascript
    Replies:
    2
    Views:
    148
  3. Suresh
    Replies:
    2
    Views:
    399
    Suresh
    Apr 22, 2004
  4. Check all checkboxes

    , Jun 19, 2005, in forum: Javascript
    Replies:
    6
    Views:
    147
    Richard Cornford
    Jun 20, 2005
  5. shankwheat

    Check All Checkboxes

    shankwheat, Mar 17, 2006, in forum: Javascript
    Replies:
    2
    Views:
    98
    Matt Kruse
    Mar 17, 2006
Loading...

Share This Page