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" />
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.