Jump to content

Forms.. Check Select All/ Unselect


jwk811

Recommended Posts

In the JS src
[code]
<!-- Begin
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "Check All"; }
}
//  End -->
[/code]


In the HTML form:
<input type="checkbox" value="Check All" onclick='this.value=check(this.form.yourid)' />Check All <br />

<input name="blah" type="checkbox" value="1" id="yourid" />
Is this script for PHP?
[code]<!-- Begin
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "Check All"; }
}
//  End -->[/code]
And this ones for HTML, correct?
[code]<input type="checkbox" value="Check All" onclick='this.value=check(this.form.yourid)' />Check All


<input name="blah" type="checkbox" value="1" id="yourid" />[/code]
The html code is what shows the checkbox's on your page. The javascript contains the functions which allows you to create a "Select All" button on your webpage.

You would place the javascript code inside <scr[b][/b]ipt type="text/javascript"></script> tags inside your <head></head> tags. Then further down the page in your form you would add the html he posted. Also, with your form make sure it has and [b]id[/b] attribute, and replace "yourid" with the id attribute of your form.

If you don't understand what I mean, post your html file and I'll/others here can add it for you.
Okay, so what I'm getting is I add the java script to the head of the html document. Then on the form as an input type I'll add <input type="checkbox" value="Check All" onclick='this.value=check([b]this.form.yourid[/b])' />Check All. And for the bold part I would have to change that correct? Could you give me an example of what I would have to change that to? Do I just list the input names? How would I list them? And am I supposed to name the form too, how would I do that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.