473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

all checkboxes should be checked in the array

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function SetAllCheckBoxes(FormName, FieldName, CheckValue)
  5. {
  6.     if(!document.forms[FormName])
  7.         return;
  8.     var objCheckBoxes = document.forms[FormName].elements[FieldName];
  9.     if(!objCheckBoxes)
  10.         return;
  11.     var countCheckBoxes = objCheckBoxes.length;
  12.     if(!countCheckBoxes)
  13.         objCheckBoxes.checked = CheckValue;
  14.     else
  15.         // set the check value for all check boxes
  16.  
  17. for(var i = 0; i < countCheckBoxes; i++)
  18.  
  19.             objCheckBoxes[i].checked = CheckValue;
  20. }
  21.  
  22. function pop()
  23. {
  24.  
  25.     alert("Do u want to delete this row?");
  26.  
  27.  
  28. }
  29.  
  30.  
  31. </script>
  32. </head>
  33. <body>
  34.  
  35. <?php include "menu.php";?>
  36.  
  37. <center><b>CONTACT INFO</b></center><br>
  38.  
  39.   <form method="post" onSubmit="<?=$PHP_SELF?>">
  40.  
  41.  <table border="0" cellpadding="0" cellspacing="0">
  42.  
  43.   <tr>
  44.     <td>
  45.         <table  border="0" cellpadding="0" cellspacing="0">
  46.             <tr>
  47.                 <td style="padding-left:20px;padding-bottom:20px;"><a href="createcontact.php" style="text-decoration:none"><input type="button" name="new" value="CREATE CONTACT"  style="width:170px;background-image:url(pink.gif)"></a></td>
  48.                 <td style="padding-left:20px;padding-bottom:20px;"><a href="createlead.php" style="text-decoration:none"><input type="button" name="new" value="CREATE LEAD"  style="width:170px;background-image:url(pink.gif)"></a></td>
  49.             </tr>
  50.  
  51.             <tr>
  52.                 <td style="padding-left:20px;"><a href="createaccount.php" style="text-decoration:none"> <input type="button" name="new" value="CREATE ACCOUNT"  style="width:170px;background-image:url(pink.gif)"></a></td>
  53.                 <td style="padding-left:20px;"> <a href="createopportunity.php" style="text-decoration:none"> <input type="button" name="new" value="CREATE OPPORTUNITY"  style="width:170px;background-image:url(pink.gif)"></a></td>
  54.             </tr>
  55.         </table>
  56.     </td>
  57.  
  58.     <td style="padding-left:120px;">
  59.         <table  cellpadding="8" cellspacing="0" with frame="box">        
  60.         <tr>
  61.             <td style="padding-left:10px;padding-bottom:20px;">FIRST NAME</td>
  62.             <td style="padding-left:60px;padding-bottom:20px;"><input type="text" name="fname"></td>
  63.         </tr>
  64.  
  65.         <tr>
  66.             <td style="padding-left:10px"><input type="submit" name="search" value="SEARCH"  style="width:80px;background-image:url(pink.gif)" ></td>
  67.             <td style="padding-left:30px"><input type="reset" name="clear" value="CLEAR"  style="width:80px;background-image:url(pink.gif)" ></td>
  68.         </tr>
  69.         </table>
  70.     </td>
  71.   </tr>
  72. </table>
  73. <br/><br/>
  74.  
  75. <b><center>CONTACT LIST </center></b>
  76.  
  77. <br/>
  78. [php][/php]
  79. <?php
  80.      include 'connect.php';
  81.      $fn= $_POST[fname];
  82.  
  83.  if(!$fn==NULL)
  84. {
  85.     $res = mysql_query("SELECT * FROM createcontact where fname LIKE '%$fn%' ");
  86. ?>  
  87.  
  88. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  89.       <input type="button"  style="width:130px;background-image:url(pink.gif)" onclick="SetAllCheckBoxes('contacts', 'chkbx', true);" value="SELECT ALL">
  90.  
  91.     <input type="button" style="width:130px;background-image:url(pink.gif)"onclick="SetAllCheckBoxes('contacts', 'myCheckbox', false);" value="SELECT NONE">
  92.  
  93.     <input type="submit" name="delete" value="DELETE"  id="delete" style="width:130px;background-image:url(pink.gif)" onClick="pop()">
  94.  
  95.  
  96.  
  97.    <?
  98. include 'connect.php';
  99. mysql_select_db('sfas',$con);
  100. if(isset($_POST['delete'])){
  101.     if(sizeof($_POST['chkbx'])){
  102.         foreach($_POST['chkbx'] AS $val){
  103.             $sql = mysql_query("DELETE FROM createcontact WHERE id=".(int)$val)or die(mysql_error());
  104.         }
  105.     }
  106.  
  107.  
  108.     if($sql)
  109.         {
  110.  
  111.          echo "record(s) deleted"; 
  112.     }
  113. }
  114.  
  115. $sel="SELECT * FROM createcontact";
  116. $result=mysql_query($sel);
  117. ?> 
  118.  
  119.   <br/><br/>
  120.  
  121.     <form name="contacts" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
  122.  <table border="1" align="center" cellpadding="0" cellspacing="0" width="900" style="border:1px solid #ffaacc;">        <tr>
  123.  
  124.  <td width="50" align="center">
  125.  
  126.         <input type="checkbox"></td>
  127.  
  128.         <td>NAME</td>
  129.         <td>TITLE</td>
  130.         <td>A/C NAME</td>
  131.         <td>EMAIL</td>
  132.         <td>PHONE NO</td>
  133.         <td>TEAM</td>
  134.         <td>USER</td>
  135.     </tr>
  136.  
  137. <?php
  138.  
  139. while($rows=mysql_fetch_array($res))
  140. {
  141.  
  142. ?>
  143.  
  144. <tr>
  145. <td width="50" align="center">
  146. <input type="checkbox" name="chkbx[]" id="checkbox_<? echo $x; ?>"  value="<? echo $rows['id']; ?>"></td>
  147.     <td> <?echo $rows['fname'];?> </td>
  148.    <td><?echo $rows['title'];?></td>
  149.     <td><?echo $rows['acname'];?></td>
  150.    <td><?echo $rows['email'];?></td>
  151.    <td><?echo $rows['phone'];?></td>
  152.        <td><?echo $rows['team'];?></td>
  153.     <td><?echo $rows['assignedto'];?></td>
  154.     </tr>
  155.  
  156. <?php
  157.    }
  158. ?>
  159.  
  160.  
  161. <? mysql_close();?>
  162.  
  163. </table>
  164.  
  165.     <? } 
  166.  
  167.     else
  168.     {
  169.         include 'connect.php';
  170. mysql_select_db('sfas',$con);
  171. if(isset($_POST['delete'])){
  172.     if(sizeof($_POST['chkbx'])){
  173.         foreach($_POST['chkbx'] AS $val){
  174.             $sql = mysql_query("DELETE FROM createcontact WHERE id=".(int)$val)or die(mysql_error());
  175.         }
  176.     }
  177.  
  178.  
  179.     if($sql){
  180.  
  181.  
  182.         echo "record(s) deleted";
  183.     }
  184. }
  185.  
  186. $sel="SELECT * FROM createcontact";
  187. $result=mysql_query($sel);
  188. ?>
  189.  
  190. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  191.  
  192.     <input type="button"  style="width:130px;background-image:url(pink.gif)" onclick="SetAllCheckBoxes('contacts', 'chkbx', true);" value="SELECT ALL">
  193.  
  194.     <input type="button" style="width:130px;background-image:url(pink.gif)"onclick="SetAllCheckBoxes('contacts', 'chkbx', false);" value="SELECT NONE">
  195.  
  196.     <input type="submit" name="delete" value="DELETE"  id="delete" style="width:80px;background-image:url(pink.gif)" onclick="pop()">
  197.  
  198.  <br/><br/>
  199.    <form name="contacts" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" onload="return false;">
  200.  
  201.  <table border="1" align="center" cellpadding="0" cellspacing="0" width="900" style="border:1px solid #ffaacc;">        <tr>
  202.  
  203.  <td width="50" align="center"><input type="checkbox"></td>
  204.  
  205.         <td>NAME</td>
  206.         <td>TITLE</td>
  207.         <td>A/C NAME</td>
  208.         <td>EMAIL</td>
  209.         <td>PHONE NO</td>
  210.         <td>TEAM</td>
  211.         <td>USER</td>
  212.     </tr>
  213.  
  214. <?php
  215.  $x = 0; 
  216. while($rows=mysql_fetch_array($result))
  217. {
  218. $x++;
  219. ?>
  220.  
  221. <tr>
  222. <td width="50" align="center">
  223. <input type="checkbox" name="chkbx[]" id="checkbox_<? echo $x; ?>"  value="<? echo $rows['id']; ?>"></td>
  224.     <td> <?echo $rows['fname'];?> </td>
  225.    <td><?echo $rows['title'];?></td>
  226.     <td><?echo $rows['acname'];?></td>
  227.    <td><?echo $rows['email'];?></td>
  228.    <td><?echo $rows['phone'];?></td>
  229.        <td><?echo $rows['team'];?></td>
  230.     <td><?echo $rows['assignedto'];?></td>
  231.     </tr>
  232.  
  233. <?php
  234.    }
  235. ?>
  236.  
  237.  
  238.  
  239. <? mysql_close();?>
  240.  
  241. </table>
  242.     <?php } ?>
  243.  
  244.  
  245. </form>
  246. </body>
  247. </html>
  248.  
  249.  
  250.  
my question is as follows
if the select all button is clicked all checkboxes should be selected so that we can delete with delete button and select none is clicked none should be selected
Mar 31 '09 #1
6 2331
acoder
16,027 Expert Mod 8TB
When you use the name, use the full correct name "chkbx[]".
Mar 31 '09 #2
hi acoder

i have changed the name as chkbx[] still it is not working
Mar 31 '09 #3
acoder
16,027 Expert Mod 8TB
Did you change it in the function call?
Expand|Select|Wrap|Line Numbers
  1. onclick="SetAllCheckBoxes('contacts', 'chkbx[]', true);"
Mar 31 '09 #4
yes i have changed it there only
Mar 31 '09 #5
Hi acoder,

I have changed it in the function call also, still its not working.

The check boxes are in the array with the help of their id the rows get deleted.

Here i need to check all the checkboxes by clicking the select all button and deselect by select none button once it gets selected i should be able to delete it with the delete button
Apr 1 '09 #6
acoder
16,027 Expert Mod 8TB
You have 4 buttons for SELECT ALL/NONE. Have you changed them all?

I tested your code in FF3 with a number of checkboxes and it works fine.

What I can suggest is that you post your code again, but the client-side version (without the PHP) as seen when you view the source in the browser.
Apr 1 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Ralph Freshour | last post by:
I have multiple checkbox's created with an array name because I have many on the same web page - their names are like: frm_chk_delete frm_chk_delete frm_chk_delete frm_chk_delete etc. Here...
3
by: Wendy S | last post by:
I have this working, but I don't think it's done efficiently or the best way: <a href="javascript:setAllAccounts(true)">check all</a> <a href="javascript:setAllAccounts(false)">clear all</a> ...
3
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
5
by: @(none) | last post by:
I have a page which is a set of CheckBoxes generated daily and thus the number of Checkboxes changes each day. What I want to do is allow the user to select one or more checkboxes and the push a...
6
by: terence.parker | last post by:
I currently have the following JS in my header: function checkall(thestate) { var checkboxes=eval("document.forms.EssayList.file_id") for (i=0;i<checkboxes.length;i++)...
8
by: Tim | last post by:
On my form I have 10 checkboxes named chkbox1,chkbox2,....chkbox10. I would have like to set it up as an array control like in VB6 where I could have chkbox(1),chkbox(2) but I think .net you have...
6
by: jeffsnox | last post by:
Hi, I have multiple checkboxes on the same form as follows: <input type='checkbox' name='cbtype' value='1'> <input type='checkbox' name='cbtype' value='2'> <input type='checkbox'...
1
by: wissenwill | last post by:
Hello! I need help to modify the following JavaScript: <script language="javascript"> var flds = "chk1,chk2,chk3,chk4".split(",") var vals = new Array(2,4,8,16) var msgs = new Array();
5
by: ameshkin | last post by:
What I want to do is very simple, but I'm pretty new at PHP and its a little hard for me. I have one page, where there are a rows of checkboxes. A button selects all checkboxes, and then...
13
by: PhpCool | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.