checkbox

A

Anonymous

Guest
hi..i already design a page something like phonebook.i need ur help because i need a script to check all the checkboxes by clicking only one button instead of doing it one by one...

here is my code:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>SMS Broadcast</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?
//include "./conn1.inc";
?>
<table width="525" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><div align="center" class="style8 style4">SMS Broadcast </div></td>
  </tr>
  <tr>
    <td height="20"> </td>
  </tr>
</table>
<table width="652" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><div align="center">
        <table width="786" height="26" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
          <tr>
            <td width="110"><div align="center" class="style1 style2"><a href="pgBroadcast.php">Broadcast SMS</a> </div></td>
            <td width="110"><div align="center" class="style3"><strong><a href="phonebook.php">My Phonebook</a></strong></div></td>
            <td width="110"><div align="center" class="style3"><strong><a href="pgScheduledBroadcast.php">My Schedule </a></strong></div></td>
            <td width="110"><div align="center" class="style3"><strong><a href="pgHistory.php">My History </a></strong></div></td>
            <td width="110"><div align="center" class="style3"><strong><a href="mymanager.php">My Manager</a> </strong></div></td>
            <td width="110"><div align="center"><span class="style3"><strong><a href="mycredit.php">My Credit </a></strong></span></div></td>
			<td width="110"><div align="center" class="style3"><strong><a href="logout.php">Logout</a></strong></div></td>
          </tr>
        </table>
    </div></td>
  </tr>
</table>
<p> </p>
<form action=
  <?php 
  if ($page==1) 
  	echo "pgBroadcast.php";
  else if ($page==2) 
  	echo "pgScheduledBroadcast.php";
  ?>
   method="post">

  <form action="pgBroadcast.php" method="post">
  <table align="center" width="720">
  	<tr>
		<td width="720" align="center" bgcolor="#DCDCDC"><strong>Personal address book</strong></td>
	</tr>
  </table>

  <div align="center">
  <table align="center" border="0" cellpadding="1" cellspacing="0" width="720">
  <tr>
		<td width="200" align="center" bgcolor="#FFFFCC"><div align="left"><strong>Group Name</strong></div></td>
		<td width="200" align="center" bgcolor="#FFFFCC"><div align="left"><strong>Username</strong></div></td>
		<td width="180" align="center" bgcolor="#FFFFCC"><div align="left"><strong>Mobile Number</strong></div></td>
		<td width="140" align="center" bgcolor="#FFFFCC"><div align="left"><strong></strong></div></td>
	</tr>
	<?php  
			$query = "Select * FROM Phonebook where Groupname='$Groupname' order by Groupname,Username asc;"; //where Groupname=$Groupname;"; 
			$result = mysql_query($query);
			
				while ($row = mysql_fetch_array($result)) 
				{ 
				$ID = $row["ID"]; 
				$X = $row["Groupname"]; 
				$Y = $row["Username"];
				$Z = $row["MobileNumber"];
			?>
			<tr>
	  		<td width="200">
			<div align="left">
			<?
			echo "<input name='zon2[]' type='checkbox' value='$Z'>";
			echo "<strong><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>";
			echo $X; 
			
		?></div></td>
		<td width="200"><div align="left"><span class="style1 style2"><? echo $Y; ?></span></div></td>
		<td width="180"><div align="left"><span class="style1 style2"><? echo $Z; ?></span></div></td>
	  	
		<td width="140" height="20" colspan="2" ><div align="right"><? 
		echo "<a href='edit.php?ID=$ID'>edit</a>::<a href='delete.php?ID=$ID' onClick=\"return confirm('Are you sure?')\">delete</a>"; echo "<br>";
		echo "</font></strong>";
		 ?> </div></td></tr>
		<? } ?>
	
  </table>
  </div>
</FORM>
<h4><center>
<form action="pgBroadcast.php" method="post">
<table border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<tr>
		<td><p align="center"><input type="Submit" value="Use Addresses" name="submit"></p></td>
	</tr>
</table>
</form>

<p> </p>
</body>
</html>

where should i put the check all script...?

thanks in advance...:)
 
hey you should google for this before posting here... Its way too common..
anyways..
Code:
function check_all( chkd) {
  for (i=0; i<document.forms['formname'].elements['chkboxname'].length; i++ ) {
    if (chkd)
       document.forms['formname'].elements['chkboxname'].checked == true;
    } else {
       document.forms['formname'].elements['chkboxname'].checked == true;
    }
  }
}
 
i already put the check all function in my coding but it didnt work..it didnt check even one checkbox..this is the check all function that i used:

Code:
<head>
<SCRIPT LANGUAGE="JavaScript">

</script>
</head>

<body>
<form name="myform" action="pgBroadcast.php" method="post">
                          $X = $row["Groupname"];
                          $Y = $row["Username"];
	          $Z = $row["MobileNumber"];

<?
echo "<input name='zon2[]' type='checkbox' value='$Z'>";
echo $X;
?>
<input type=button name="CheckAll" value="Check All" onClick="checkAll(document.myform.zon2[])">
<input type=button name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(document.myform.zon2[])">
</form>
</body>


thanks...
 
Your checkbox is already referenced in the Javascript code, so you don't need to pass that stuff when calling the function.
Call the function like this (Example):
Code:
checkAll(true); -> To check all
checkAll(false); -> To uncheck all
Also replace the last line of your js code with checked == false, so you'll be able to uncheck the checkboxes.

In last case, try using as your checkbox name in the js code zon2 instead of zon2[].
 
please excuse me :?
I'm sorry I missed some thing imp...
here it is

Code:
function checkAll(chkd)
{ 
   for (i=0; i<document.forms['myform'].elements['zon2[]'].length; i++ )
   {   
      if (chkd)
      {     
         document.forms['myform'].elements['zon2[]'][i].checked == true;   
      } else
      {   document.forms['myform'].elements['zon2[]'][i].checked == true; } 
   }
}
 
sorry...my coding still didnt work.. :(

Code:
<SCRIPT LANGUAGE="JavaScript">
</script>



<table border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<tr>
		<td><input type=button name="CheckAll" value="Check All" onClick="checkAll(document.myform.zon2[])"></td>
		<td><input type=button name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(document.myform.zon2[])"></td>
		<td><p align="center"><input type="Submit" value="Use Addresses" name="submit"></p></td>
	</tr>
</table>
 
hey !!!
check the function..
the function accepts boolean as an argument...

so ...

Code:
       <td><input type=button name="CheckAll" value="Check All" onClick="checkAll(true)"></td>
       <td><input type=button name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(false)"></td>

now it SHOULD work!!
 
Back
Top