Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

checkbox

Javascript coding ..

Moderators: macek, egami, gesf

checkbox

Postby whitemoss » Wed May 25, 2005 5:50 pm

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: Select all

<!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">&nbsp;</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>&nbsp;</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>&nbsp;</p>
</body>
</html>



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

thanks in advance...:-)
whitemoss
New php-forum User
New php-forum User
 
Posts: 55
Joined: Thu Apr 14, 2005 1:28 am
Location: Malaysia

Postby ruturajv » Thu May 26, 2005 2:33 am

hey you should google for this before posting here... Its way too common..
anyways..
Code: Select all
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;
    }
  }
}
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby whitemoss » Thu May 26, 2005 6:05 pm

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: Select all
<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkAll(chkd)

   for (i=0; i<document.forms['myform'].elements['zon2[]'].length; i++ )
   {   
      if (chkd)
      {     
         document.forms['myform'].elements['zon2[]'].checked == true;   
      } else
      {   document.forms['myform'].elements['zon2[]'].checked == true; } 
   }
}
///  End -->
</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...
whitemoss
New php-forum User
New php-forum User
 
Posts: 55
Joined: Thu Apr 14, 2005 1:28 am
Location: Malaysia

Postby gesf » Sat May 28, 2005 4:06 pm

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: Select all
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[].
User avatar
gesf
Moderator
Moderator
 
Posts: 1718
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby ruturajv » Sun May 29, 2005 7:32 pm

please excuse me :?
I'm sorry I missed some thing imp...
here it is

Code: Select all
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; }
   }
}
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby whitemoss » Mon May 30, 2005 12:50 am

sorry...my coding still didnt work.. :(

Code: Select all
<SCRIPT LANGUAGE="JavaScript"><!-- Begin
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 == false; }   
   }
}
///  End -->
</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>
whitemoss
New php-forum User
New php-forum User
 
Posts: 55
Joined: Thu Apr 14, 2005 1:28 am
Location: Malaysia

Postby ruturajv » Mon May 30, 2005 7:47 pm

hey !!!
check the function..
the function accepts boolean as an argument...

so ...

Code: Select all
       <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!!
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India


Return to JavaScript

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron