473,769 Members | 6,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

all checkboxes should be checked in the array

27 New Member
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 2366
acoder
16,027 Recognized Expert Moderator MVP
When you use the name, use the full correct name "chkbx[]".
Mar 31 '09 #2
ahilar12
27 New Member
hi acoder

i have changed the name as chkbx[] still it is not working
Mar 31 '09 #3
acoder
16,027 Recognized Expert Moderator MVP
Did you change it in the function call?
Expand|Select|Wrap|Line Numbers
  1. onclick="SetAllCheckBoxes('contacts', 'chkbx[]', true);"
Mar 31 '09 #4
ahilar12
27 New Member
yes i have changed it there only
Mar 31 '09 #5
ahilar12
27 New Member
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 Recognized Expert Moderator MVP
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
2842
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 is my code line that creates each checkbox (the php variable get
3
1430
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> function setAllAccounts(value) { for(i = 0 ; i < document.forms.accounts.length; i++ ) { document.forms.accounts.checked = value; } }
3
1830
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 construct a checkbox array in a survey form where one of the choices is "No Preference" which is checked by default. If the victim chooses other than "No Preference", I'd like to uncheck
5
5895
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 "Done" button and then have a script which uses a "for" loop to check the status of each box. The code I use for this is Sample checkbox HTML <P STYLE="margin-left: 1.5in"><INPUT TYPE=CHECKBOX NAME="CheckBox0"
6
2847
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++) checkboxes.checked=thestate } This works fine - but the problem is that it doesn't work with my
8
42184
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 to have specific names for each control. All 10 of the boxes are in a groupbox. What I'm trying to do is when I hit a button it will loop through all the checkboxes to see which ones are checked and add that checkbox name to a string. Something...
6
14759
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' name='cbtype' value='3'> I'm wanting to re-display the same checkboxes, but if the user previously checked one of them then I want it automatically checked on
1
4584
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
4197
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 presses delete. When delete is pressed, I want to go to a next page and run a sql command for every single box thats checked. The checkboxes store a value, and multiple boxes can be checked.
13
3092
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 checkboxes (code pasted below). But if name of the checkbox array is 'chkbx_ary' then it's failing. I want the name to be 'chkbx_ary' because I want to access this array at server side. Though one may not require to see php part but I'm still pasting...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7409
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.