How to check all the check box???

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

acswilson
New php-forum User
New php-forum User
Posts: 18
Joined: Thu Jul 17, 2003 7:42 am

How to check all the check box???

Postby acswilson » Thu Aug 21, 2003 8:47 pm

I used the array to display the check boxes.

Code: Select all

<? include ("./verify_session1.php"); ?>
<? setcookie("username1", $username1); ?>
<html>
<head>
   <SCRIPT language=JavaScript
   src="check.js"></SCRIPT>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#12A9E2" text="#000000">
<div align="left">
<p><font face="Arial Narrow" size="4">Welcome, <b>
   <?php
      (" $HTTP_COOKIE_VARS as $username1" );
      print ( "$username1" );
   ?></b> ! </font></p>   
<p align="center"> <font color = "Blue" align=left><font color="#FFFFFF" size="4" face="Arial Narrow"><b>
This is for joining societies.</b></font></font> </p></div>

<?
$Connect = mysql_connect("localhost", "root", "");
mysql_select_db("mw");
$result = mysql_query("select * from society1 order by society");
?>

<TABLE Border=0 width=200 align="left" height="63" >
  <TR>
    <TD >
      <center>
        <FORM action = "society_confirm1.php" method ="post">
          <p align="left">
            <?
            while ($number_of_array = mysql_fetch_array($result))
            {
               echo "<tr><td width='3%' style='border-style: none; border-width: medium'><input type='checkbox' name='society[]' value='$number_of_array[society]'></td><td width='18%' style='border-style: none; border-width: medium' colspan='2'><font color='#111111'>$number_of_array[society]</font></td></tr>";
            }
         ?>
          </p><div align="left"><BR>
        <INPUT TYPE = "submit" VALUE = "Submit" align = middle >
          <INPUT type = "reset" VALUE = "Clear" align = middle>
          </div>
        </FORM>
      </center>
    </TD>
  </TR>
</TABLE>
</body>
</html>

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Fri Aug 22, 2003 1:09 am

Using the attribute "checked":

Code: Select all

<input name="blahblah" type="checkbox" value="blahblah" checked>

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Postby Joel » Fri Aug 22, 2003 4:52 am

I'm not too familiar with javascript and I'm assuming you want something like hotmail where you click the top check and all of them get checked?

Use something like this for the check box which makes all buttons be checked

Code: Select all

<input type="checkbox" OnMouseClick="society[].checked=true">
[/code]

sigix
php-forum Active User
php-forum Active User
Posts: 364
Joined: Mon Jul 14, 2003 9:39 pm
Location: /Earth/Xion

Postby sigix » Fri Aug 22, 2003 9:29 pm

they get all the check box through a loop
and then set their value to true
psudo
when main check button is checked
i =0
for all the check boxes on display for email i to n ..
check[i].checked=true

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Select all

Postby ruturajv » Fri Aug 22, 2003 10:53 pm

Code: Select all

<script language=javascript>
function select_all()
{
len = document.elementname.length;

for (i=0;i<len;i++) {
document.elementname[i].checked = true;
}

}
</script>
<input type=button value='Select All' onClick="select_all();">

acswilson
New php-forum User
New php-forum User
Posts: 18
Joined: Thu Jul 17, 2003 7:42 am

Sorry I still can't do it !!!!

Postby acswilson » Tue Aug 26, 2003 8:00 pm

i think the last one, which using the javascript is work but i found that the javascript coding may be got something need to be change, is it? please tell me.

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

javascript

Postby ruturajv » Tue Aug 26, 2003 10:41 pm

the elementname is the name of the element eg

Code: Select all

<input type="checkbox" name="someid">

here the someid is the name of the element

but be sure you keep the name of the element same if you have to select all the check boxes

acswilson
New php-forum User
New php-forum User
Posts: 18
Joined: Thu Jul 17, 2003 7:42 am

still can't

Postby acswilson » Wed Aug 27, 2003 7:36 am

please help me change on the coding that i had post up, provide the check all button or something like hotmail select all check box.

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Code

Postby ruturajv » Wed Aug 27, 2003 9:54 pm

here this should satisfy you fully :D :D

Code: Select all

<html>
<head>
<script language=javascript>
function select_all()
{
var len = document.form1.someid.length;

for (i=0;i<len;i++) {
document.form1.someid[i].checked = true;
}

}
</script>
</head>
<body>
<FORM METHOD=POST Name="form1">
<INPUT TYPE="checkbox" NAME="someid"><br>
<INPUT TYPE="checkbox" NAME="someid"><br>
<INPUT TYPE="checkbox" NAME="someid"><br>
<INPUT TYPE="checkbox" NAME="someid"><br>
<INPUT TYPE="checkbox" NAME="someid"><br>
<INPUT TYPE="checkbox" NAME="someid"><br>
<INPUT TYPE="checkbox" NAME="someid"><br>
</FORM>
<p>
<input type=button value='Select All' onClick="select_all();">


you can make a new function copy all the contents of select_all function and just replace checked=true for false and you will get Deselect all
:idea:


Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot] and 2 guests