Jump to content

Archived

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

jwk811

Forms.. Check Select All/ Unselect

Recommended Posts

How do you make it so in a form you can "select all" or "unselect all" without having to submit or reload? Please help!

Share this post


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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
That's javascript (the first one) . Put it in the head section between script tags.

Share this post


Link to post
Share on other sites
Which one should I use? I will try the HTML because I don't know anything about javascript, will that work okay?

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
Not sure why there's a return value to that function call -- you'll have to go through all checkboxes, so an ID is somewhat meaningless.

Share this post


Link to post
Share on other sites
I'm not sure what you're having trouble with at this point.

Share this post


Link to post
Share on other sites

×

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.