Forms "Check All" checkboxes

S

Steve

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
 
J

Jeff Thies

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

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
 
O

O

Steve said:
Is there a nonJava way to check all the checkboxes on a page?

You can use the selected attribute on eact input tag:

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

O

Steve said:
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.
 
D

Decaf

Steve said:
Is there a nonJava way to check all the checkboxes on a page?

You can use the selected attribute on eact input tag:

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.
 
D

Decaf

Steve said:
Is there a nonJava way to check all the checkboxes on a page?

You can use the selected attribute on eact input tag:

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.
 
S

Steve

O said:
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
 
J

Jeff Thies

Steve said:
O said:
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
 
F

floortje

Steve said:
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">

:)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top