Jump to content


Photo

Forms.. Check Select All/ Unselect


  • Please log in to reply
9 replies to this topic

#1 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 25 September 2006 - 01:10 AM

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

#2 extrovertive

extrovertive
  • Members
  • PipPipPip
  • Advanced Member
  • 235 posts

Posted 25 September 2006 - 01:14 AM

In the JS src
<!-- 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 -->


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" />

#3 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 25 September 2006 - 01:20 AM

Is this script for PHP?
<!-- 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 -->
And this ones for HTML, correct?
<input type="checkbox" value="Check All" onclick='this.value=check(this.form.yourid)' />Check All 


<input name="blah" type="checkbox" value="1" id="yourid" />


#4 yonta

yonta
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 25 September 2006 - 02:17 AM

That's javascript (the first one) . Put it in the head section between script tags.
do it, do it right, do it right now

#5 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 25 September 2006 - 10:55 AM

Which one should I use? I will try the HTML because I don't know anything about javascript, will that work okay?

#6 FrOzeN

FrOzeN
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 25 September 2006 - 11:30 AM

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 <script 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 id 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.

#7 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 26 September 2006 - 12:39 AM

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(this.form.yourid)' />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?


#8 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 26 September 2006 - 02:30 AM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#9 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 27 September 2006 - 12:15 AM

huh

#10 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 27 September 2006 - 06:58 PM

I'm not sure what you're having trouble with at this point.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users